题解 | 获取指定客户每月的消费额

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")



全部评论

相关推荐

不愿透露姓名的神秘牛友
12-26 12:24
特宝研发 软件开发 22*13 硕士985
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务