SELECT CASE
WHEN aab301 IS not NULL and akb020 is null THEN
'小计'
WHEN aab301 IS NULL THEN
'合计'
ELSE
'' ||aab301
END aab301,akb020,aab001,sum(akc264) from kc24_zy
group by grouping sets ((aab301),(aab301,akb020,aab001),'');
WHEN aab301 IS not NULL and akb020 is null THEN
'小计'
WHEN aab301 IS NULL THEN
'合计'
ELSE
'' ||aab301
END aab301,akb020,aab001,sum(akc264) from kc24_zy
group by grouping sets ((aab301),(aab301,akb020,aab001),'');
本文介绍了一个具体的SQL查询案例,展示了如何使用SELECT CASE语句来处理不同的条件组合,并通过GROUP BY和GROUPING SETS进行数据分组汇总。此案例有助于理解复杂查询的构建方式。
951

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



