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

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



全部评论

相关推荐

点赞 评论 收藏
分享
09-30 15:27
已编辑
成都工业学院 企业文化
Morpheus_:候选人:还需要测验武力值?
投递腾讯等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务