题解 | #计算商城中2021年每月的GMV#

计算商城中2021年每月的GMV

https://www.nowcoder.com/practice/5005cbf5308249eda1fbf666311753bf

select date_format(event_time,"%Y-%m") dt,sum(total_amount) GMV
from tb_order_overall
where status !=2 and year(event_time)=2021
group by dt
having sum(total_amount) >=100000
order by 2

明确MySQL语句的运行顺序,明确同个查询语句中 分组函数不能直接用在where语句后面

select 5

..

from 1

..

where 2 ..第一次过滤

.. --这里不能直接使用分组函数

group by 3 --分组,先分组才能试用分组函数

...

having 4 --第二次的过滤

..

order by 6

全部评论

相关推荐

03-26 12:00
已编辑
门头沟学院 Java
offer魅魔_oc...:100-200每天,你还要倒贴100
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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