select time,sum(t_amount) as total
from(
    select t_id,substring(t_time,1,7) time,t_amount
    from trade,customer
    where c_name='Tom' and t_time like '2023%' and c_id=t_cus 
    and t_id in (select max(t_id)
                from trade
                group by t_time) 
) b
group by time
order by time 

1 按照月份统计消费额,通过截取t_time并分组,使用sum统计total字段

2 对于可能出现的相同时间的记录保留最后一条,这一题在这里挖了一个坑。解决办法:直接使用distinct不能得到其他字段,所以按照t_time分组,根据t_id选出不重复的记录