如何实现多个Select中有多个case when的行转列查询。 返回
SqlSugar
沟通中
1
951
环宇 发布于6天前
悬赏:0 飞吻
SQL语句如下,其中A.BFB_Type是不固定的字段,需要从另一个张表取出来。
请问如何在SqlSugar中实现。
select A.XM_No,B.XM_Name,
sum(case A.BFB_Type when '诊断' then A.BFB else 0 end) as 诊断,
sum(case A.BFB_Type when '执行' then A.BFB else 0 end) as 执行,
sum(case A.BFB_Type when '护理' then A.BFB else 0 end) as 护理,
sum(case A.BFB_Type when '支出' then A.BFB else 0 end) as 支出,
sum(case A.BFB_Type when '其他' then A.BFB else 0 end) as 其他
from ItemBFB A inner join Item B on A.XM_No = B.XM_No and A.Fyear = B.Fyear
where A.BM_No='100301'
group by A.XM_No,b.XM_Name
order by A.XM_No
热忱回答(1)
-
fate sta VIP06天前
看文档:行转列
0 回复