表结构如下id type name
1 AAA QWE
2 AAA QWE
3 AAA WQE
4 BBB REE
5 BBB RRR
6 CCC EEE排序是按照type,id 升序排列,我怎么查到所有type所对应的name的第一条数据呢?
求大侠们帮忙
1 AAA QWE
2 AAA QWE
3 AAA WQE
4 BBB REE
5 BBB RRR
6 CCC EEE排序是按照type,id 升序排列,我怎么查到所有type所对应的name的第一条数据呢?
求大侠们帮忙
(select id,type,name,row_number()over(partition by type order by id,type) rn
from table)
where rn=1
select * from tab t where id=(select min(id) from tab where type=t.type);
select id,type,name
from (select id,type,name,row_number() over(partition by name order by name,rowid) rn
from tb) a
where a.rn=1