select date_format(t_time,'%Y-%m') time # substr(t_time,1,7) time ,sum(t_amount) total from trade t1 left join customer t2 on t1.t_cus=t2.c_id where c_name='Tom' and year(t_time)=2023 and t_type=1 group by date_format(t_time,'%Y-%m') order by date_format(t_time,'%Y-%m'); # 1.SELECT列表中的非聚合列必须出现在GROUP BY子句中,任何没有使用聚合函数(如SUM, COUNT, MAX等)的列,必须明确包含在GROUP BY子句中 # 2.HAVING条件和ORDER BY子句中的列必须满足以下条件之一: # 出现在GROUP BY子句中 # 是聚合函数的参数 # 是GROUP BY中列的功能性依赖列(MySQL 5.7.5+支持) # 本题忽略了order by的强制要求,并复习了日期处理函数。