日期:2014-05-18 浏览次数:20667 次
select co_code,sum(case when receive_date between <%param("qsrq")%> and <%param("jsrq")%> then revenue_num else 0 end)*100 benyue,sum(revenue_num)*100 leijishu from v_nt_bill_baobiaoqushu where fiscal=<%substring(param('jsrq'),1,4) %> and receive_date<=<%param("jsrq")%> and co_code in (<%getcode(param('gsdm'))%>) group by co_code order by co_code union all --用union all select co_code,sum(case when receive_date between <%param("sqsrq")%> and <%param("sjsrq")%> then revenue_num else 0 end)*100 sbenyue,sum(revenue_num)*100 sleijishu from v_nt_bill_baobiaoqushu where fiscal=<%substring(param('sjsrq'),1,4) %> and receive_date<=<%param("sjsrq")%> and co_code in (<%getcode(param('gsdm'))%>) group by co_code order by co_code
------解决方案--------------------
select ...,
sum(case when receive_date<=date1 and 原条件 then ... else 0 end)*100 benyue,
sum(case when receive_date<=date2 and 原条件 then ... else 0 end)*100 sbenyue,
sum(case when receive_date<=date1 then receive_num else 0 end) leijishu,
sum(case when receive_date<=date2 then receive_num else 0 end) sleijishu
from ...
where ...
这里的where条件中没有receive_date<=条件。
------解决方案--------------------
select co_code,sum(case when receive_date between <%param("qsrq")%> and <%param("jsrq")%> then revenue_num else 0 end)*100 benyue,sum(revenue_num)*100 leijishu from v_nt_bill_baobiaoqushu where fiscal=<%substring(param('jsrq'),1,4) %> and receive_date<=<%param("jsrq")%> and co_code in (<%getcode(param('gsdm'))%>) group by co_code union all select co_code,sum(case when receive_date between <%param("sqsrq")%> and <%param(&quo