sql 筛选两个字段的唯一

2024-12-27 04:11:46
推荐回答(2个)
回答1:

select * from (select *,row_number() over(partition by 用途 order by 产品用途表ID row_num) from 产品用途表) a where row_num=1
这是sql server的写法。oracle需要把row_number修改成dense_rank

回答2:

产品用途表 字段 id name foruse

select id,name,foruse
from 产品用途表 a
where not exists (select 1 from 产品用途表 b where a.name = b.name and a.foruse = b.foruse and a.id < b.id)