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

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

https://www.nowcoder.com/practice/ed04f148b63e469e8f62e051d06a46f5

select 
    date_format(t.t_time,'%Y-%m') as time,
    sum(case when t.t_type = 1 then t.t_amount else 0 end ) as total
    from trade t
    inner join customer c
    on c.c_id = t.t_cus
    where year(t.t_time) = 2023 and c.c_name = 'Tom'
    group by time
    order by time asc

按照计算出来的time字段来分组,该字段就是2023+月份的形式

全部评论

相关推荐

找工作勤劳小蜜蜂:矛盾是没有实习,就是没实战经验,公司不想要,公司不要,你就没有实习,你就进入死循环,另外你的项目不是社会现在有大量岗位存在行业用的,云存储人员早就饱和。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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