我有一个这样的表(EXPENSE
(:
年 | 月 | 日期 | 金额拆分类型 | ||
---|---|---|---|---|---|
2020 | 21 | 100 | YA|||
2020 | 2 | 1 | 100 | Y | A|
2020 | 2 | 100 | N | A | |
2020 | 3 | 21 | 100 | YA | |
2020 | 3 | 23 | 100 | YB | |
2020 | 3 | 14 | 100 | Y | A
只需重复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;