select @rownum:=@rownum+1 AS rownum , a.date as date,
sum(case when reconciliationTypeStr='+' then a.value else 0 end) as incomeAmount,
sum(case when reconciliationTypeStr='-' then a.value else 0 end) as payAmount
from act_reconciliation a , (SELECT @rownum:=0) r where 1=1 $P!{condition}
group by a.date
order by rownum $P!{paging}
sum(case when reconciliationTypeStr='+' then a.value else 0 end) as incomeAmount,
sum(case when reconciliationTypeStr='-' then a.value else 0 end) as payAmount
from act_reconciliation a , (SELECT @rownum:=0) r where 1=1 $P!{condition}
group by a.date
order by rownum $P!{paging}
本文介绍了一种使用SQL进行复杂财务数据汇总的方法,通过案例演示如何利用CASE WHEN语句按日期分组计算收入和支出总额。

被折叠的 条评论
为什么被折叠?



