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

select

    case

        when a.月份 < 10 then concat ('2023', '-', '0', 月份)

        else concat ('2023', '-', 月份)

    end time,

    sum(t_amount) total

from

    (

        select

            t_time,

            t_amount,

            c_name,

            month (t_time) 月份

        from

            test.customer cu

            join test.trade tr on cu.c_id = tr.t_cus

        where

            c_name = 'Tom'

            and year (t_time) = 2023

            and t_type = 1

    ) a

group by

    a.月份

order by

    a.月份

土办法

全部评论
select time, sum(t_amount) total from ( select date_format (t_time, '%Y-%m') time, t_time, t_amount, c_name, month (t_time) 月份 from test.customer cu join test.trade tr on cu.c_id = tr.t_cus where c_name = 'Tom' and year (t_time) = 2023 and t_type = 1 ) a group by a.time, a.月份 order by a.月份 用date_format做
点赞 回复 分享
发布于 01-17 22:23 贵州

相关推荐

Beeee0927:是缅甸园区吗
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 12:05
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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