表结构如下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.   

    select id,type,name
    (select id,type,name,row_number()over(partition by type order  by id,type) rn  
      from table)
    where rn=1
      

  2.   


    select * from tab t where id=(select min(id) from tab where type=t.type);
      

  3.   


    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
      

  4.   

    select * from tb  a where not exists(select 1 from tb b where a.type=b.type and a.id>b.id)