SQL热题281
该题是在278的基础上,新增了一列,显示客户端的名字,如果客户端是0,则显示未null。
left join本身具备左表有数据,然而右表没有数据时自动填充0的功能,因此我们在上一题的基础上建立完临时表后使用left join工具即可。代码如下:
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)cnt from order_info
where date > '2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed'
)t left join client as c on c.id = t.client_id
where t.cnt >= 2
order by t.id ASC
#笔试#