知识点

  1. 窗口函数和之前一样的
  2. 因为客户端id可能没有出现null值所以连接时用左连接连接client表

代码

select t.id, t.is_group_buy, c.name as client_name
from (
    select id, is_group_buy, client_id, 
    count(*) over (partition by user_id) as cnt
    from order_info
    where date > '2025-10-15'
    and product_name in ('C++', 'Python', 'Java')
    and status = 'completed'
    ) as t
left join client as c 
on c.id = t.client_id
where t.cnt >= 2
order by t.id