题解 | 获取指定客户每月的消费额
select
case
when a.月份 < 10 then concat ('2023', '-', '0', 月份)
else concat ('2023', '-', 月份)
end time,
sum(t_amount) total
from
(
select
t_time,
t_amount,
c_name,
month (t_time) 月份
from
test.customer cu
join test.trade tr on cu.c_id = tr.t_cus
where
c_name = 'Tom'
and year (t_time) = 2023
and t_type = 1
) a
group by
a.月份
order by
a.月份
土办法