col1                col2                 id
记录1              hi                      ok                  1
记录2              hi                      nok                2
记录3              hi                      ok                  3符合要求的记录为记录1、记录2 

解决方案 »

  1.   

    with m as (
    select col1 , col2 , id , row_number() over(partition by col1,col2 order by id) rn )
    from mytable 
    )
    select col1 , col2 , id from m where rn = 1 
      

  2.   

    楼上正解。此外,也可以写成:
    select col1,col2,id from (
    select col1 , col2 , id , row_number() over(partition by col1,col2 order by id) rn )
    from mytable 
    )
     where rn = 1;
    或也可以通过其他方法实现。
      

  3.   

    select col1,col2 from mytable group by col1,col2;这样行吗,效率方面是不是差了