方法一:用case when
with t_base as ( select id,user_id,product_name,status,client_id,date,is_group_buy, cnt from (select id,user_id,product_name,status,client_id,date,is_group_buy, count(*) over(partition by user_id) as cnt from order_info where product_name in ('c++','java','python') and status = 'completed' and date > '2025-10-15') as t1 where cnt >= 2) select id,is_group_buy, case client_id when '1' then 'PC' when '2' then 'Android' when '3' then 'IOS' when '4' then 'H5' else 'None' end from t_base order by id
方法二:左连接
with t_base as ( select id,user_id,client_id,is_group_buy from (select id,user_id,product_name,status,client_id,date,is_group_buy, count(*) over(partition by user_id) as cnt from order_info where product_name in ('c++','java','python') and status = 'completed' and date > '2025-10-15') as t1 where cnt >= 2) select t2.id,is_group_buy,name from (select id,is_group_buy,client_id from t_base) as t2 left join client on t2.client_id = client.id order by id