83) 牛客的课程订单分析(七)

牛客的课程订单分析(七)

http://www.nowcoder.com/questionTerminal/d6f4a37f966145da8900ba9edcc4c068

同一个代码块无限用,好耶!

select
case when o.is_group_buy = 'Yes' then 'GroupBuy' else c.name end source,
count(*) cnt
from order_info as o left join client as c
on o.client_id = c.id
where o.user_id in 
(select user_id
from order_info
where date >'2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed'
group by user_id
having count(id) > 1)
and o.date > '2025-10-15'
and o.product_name in ('C++','Java','Python')
and o.status = 'completed'
group by o.client_id
order by source asc;
SQL 文章被收录于专栏

SQL

全部评论
这个mysql里跑出来是不对的 o.is_group_buy不在聚合列里也不属于聚合函数
点赞 回复 分享
发布于 2021-04-23 14:50
我和你写的一摸一样,哈哈哈
点赞 回复 分享
发布于 2021-09-21 15:45
select (case when t1.name is null then 'GroupBuy' else t1.name end) source,count(client_id) from client t1 right join ( select *,count(id) over(partition by user_id) as number from order_info where datediff(date,"2025-10-15")>0 and status="completed" and product_name in ("C++","Java","Python") ) t2 on t1.id=t2.client_id where t2.number >1 group by t1.name order by (case when t1.name is null then 'GroupBuy' else t1.name end);
点赞 回复 分享
发布于 2021-11-02 16:25
为什么o最后还要取日子大于,那些限制?前面不是取过一次了?
点赞 回复 分享
发布于 2021-12-15 20:52
这个在mysql环境不行
点赞 回复 分享
发布于 2022-06-13 13:52
倒数第二行改成group by source 就行了
点赞 回复 分享
发布于 2022-06-17 07:06
select case when o.is_group_buy = 'Yes' then 'GroupBuy' else c.name end source, count(*) cnt from order_info o left join client c on o.client_id = c.id where o.user_id in (select user_id from order_info where date > '2025-10-15' and status = 'completed' and product_name in ('C++','Java','Python') group by user_id having count(id) >= 2) and o.date > '2025-10-15' and o.status = 'completed' and o.product_name in ('C++','Java','Python') group by source order by source 这样就行了
点赞 回复 分享
发布于 2023-12-12 17:52 北京

相关推荐

22 收藏 评论
分享
牛客网
牛客企业服务