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

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

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

select
date_format(t_time,'%Y-%m') time
# substr(t_time,1,7) time
,sum(t_amount) total
from trade t1
left join customer t2
on t1.t_cus=t2.c_id
where c_name='Tom'
and year(t_time)=2023
and t_type=1

group by date_format(t_time,'%Y-%m')
order by date_format(t_time,'%Y-%m');
# 1.SELECT列表中的非聚合列必须出现在GROUP BY子句中,任何没有使用聚合函数(如SUM, COUNT, MAX等)的列,必须明确包含在GROUP BY子句中
# 2.HAVING条件和ORDER BY子句中的列必须满足以下条件之一:
# 出现在GROUP BY子句中
# 是聚合函数的参数
# 是GROUP BY中列的功能性依赖列(MySQL 5.7.5+支持)

# 本题忽略了order by的强制要求,并复习了日期处理函数。

全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务