执行此操作的SQL是什么?我想按具有特定条件的列进行分组



我有一个这样的表(EXPENSE(:

金额拆分YAAYYA
日期类型
2020 21 100
2020 2 1 100 Y
2020 2 100 N A
2020 3 21 100A
2020 3 23 100B
2020 3 14 100 Y

只需重复group by:的表达式

select year, month,
(case when split = 'Y' then 31 else date end),
sum(amount), split, type
from EXPENSE
group by year, month, (case when split='Y' then 31 else date end),
split, type;

最新更新