某字段重复,其他字段值不同时,按重复字段分组只取一条的sql语句:
tabel:
a: | b: |
1 | 1 |
1 | 2 |
1 | 3 |
2 | 1 |
2 | 2 |
select tmp.* from (select a,b,row_number() OVER(PARTITION BY a ORDER BY b) AS rownum from tabel) temp where tmp.rownum = 1;
select tmp.v,tmp.f from (select distinct a as v,b as f,row_number() over(partition by a order by b as rownum from tabel where n ='%s' ) tmp where tmp.rownum = 1;
输出:
a: | b: |
1 | 1 |
2 | 1 |