题解 | 获取指定客户每月的消费额
SELECT DATE_FORMAT(re.time, "%Y-%m") as time, SUM(re.t_amount) AS total FROM ( SELECT t_time as time, t_amount FROM trade LEFT JOIN customer ON trade.t_cus = customer.c_id WHERE customer.c_name = "Tom" AND YEAR (trade.t_time) = 2023 AND trade.t_type = 1 GROUP BY t_amount, t_time ) as re GROUP BY DATE_FORMAT(re.time, "%Y-%m") ORDER BY DATE_FORMAT(re.time, "%Y-%m")