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

select
    time,sum(if(t_type = 1,t_amount,0)) as total
from(
    select substring_index(t_time,"-",2) as time, t_type , t_amount,c_name
    from(
        select *
        from trade t
        inner join customer c on t.t_cus =c.c_id
    ) a
    where year(t_time) = 2023
) b
where c_name = 'Tom'
group by time
order by time

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务