select runningid,runningname,payin=(case paytype when 'in' then paytotal else 0 end),payout=(case paytype when 'out' then paytotal else 0 end) from
(
select paytype,sum(pay) as paytotal,runningid,runningname from
(
select paytype,pay,runningid,runningname from
(
select paytype='in',pay,runningid,runningname from f_payi where runningid in (select id from f_running where deptid=@deptid)
union
select paytype='out',pay,runningid,runningname from f_payo where runningid in (select id from f_running where deptid=@deptid)
) a
) b group by paytype,runningid,runningname
) c
使用case指定查询结果的字段
最新推荐文章于 2021-04-21 16:46:22 发布