题解 | #牛客的课程订单分析(六)#

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

http://www.nowcoder.com/practice/c5736983c322483e9f269dd23bdf2f6f

首先还是新建个表temp来存条件筛选之后的原表并加上根据user_id分组后每组的count。
然后将temp和client用left join连接,并限制每组count大于等于2.然后用if判断client_id是否为0,client_id=0说明is_group_buy=Yes,这种情况下client name就是null,反之就是正常client name。

with temp as
(select id, user_id, date, client_id, is_group_buy,
count(id) over (partition by user_id) as cnt
from order_info
where (product_name = "C++" or product_name = "Java" or product_name = "Python")
      and date > "2025-10-15" and status = "completed")
      
select t.id, t.is_group_buy, if(t.client_id = 0, NULL, c.name)
from temp as t left join client as c
on c.id = t.client_id 
where t.cnt >= 2
order by t.id

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 12:10
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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