ID  Value
1   89
1   92
1   78
2   96
2   99
3   72
3   94
4   88
==========
输出结果
ID Value
1   89
2   96
3   72
4   88
输出结果是每一个分组的第一行,该如何写?select ID,Value from tab_1 

解决方案 »

  1.   

     select ID,Value from tab_1 group by id,Value;
      

  2.   

    select sub.id, sub.value from
    (with a as (select '1' as ID, '89' as value from dual
    union all
    select '1','92' from dual
    union all
    select '1','78' from dual
    union all
    select '2','96' from dual
    union all
    select '2','99' from dual
    union all
    select '3','72' from dual
    union all
    select '3','94' from dual
    union all
    select '4','88' from dual)
    select id,value,row_number() over (partition by id order by id) cnt from a) sub
    where sub.cnt = 1;
      

  3.   

    oracle中有个row_number的函数。可以试一试这个函数