两层查询

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

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

select 
    user_id,
    first_buy_date,
    cnt
from 
(select
    user_id,
    min(date) first_buy_date,
    sum(case status when 'completed' then 1 else 0 end) cnt

from
    order_info
where
     date > '2025-10-15'
     and
     (product_name = 'Python' || product_name = 'Java' || product_name = 'C++')
group by user_id
) t1
where cnt >= 2
order by user_id

通过子查询获取 user_id,最小的date,以及completed,外查询pai'x

全部评论
product_name = 'Python' || product_name = 'Java' || product_name = 'C++' 换成 product_name in ('C++','Java','Python') 会不会有影响
点赞
送花
回复
分享
发布于 2021-06-02 10:10

相关推荐

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