题解 | 获取指定客户每月的消费额
获取指定客户每月的消费额
https://www.nowcoder.com/practice/ed04f148b63e469e8f62e051d06a46f5
日期格式转换函数:date_format(时间,'%Y-%m'),将时间转换为‘年-月’形式,由于时间数据具有标准格式,以下代码直接字符串剪切前七位。日期筛选那可以用year(时间)=年份
select left(t_time,7) time,sum(t_amount) total from trade t join customer c on t.t_cus=c.c_id where t_type=1 and c_name='Tom' group by time having time between '2023-01' and '2023-12' order by time