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

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

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

# 如果用到分组操作,select语句中的非聚合字段必须出现在group by中的
# 比如分组是month(t_time),select是substring_index(t_time,'-',2)也不行
# 此外还可以用date_format(t_time,'%Y-%m')来设置时间格式

select substring_index(t_time,'-',2) time, sum(t_amount) total
from trade a
inner join customer b
on a.t_cus = b.c_id
where c_name = 'Tom' and year(t_time)=2023 and t_type = 1
group by time
order by time;

我是用substring_index取子串来完成题目时间格式要求的,此外还可以用date_format(t_time,'%Y-%m')来实现。

全部评论

相关推荐

Elastic90:公司不要求加班,但 又不允许你准点下班,经典又当又立
点赞 评论 收藏
分享
Yki_:以下条件优先录用: 喜欢去缅北当猪仔的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务