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
楼上正解。此外,也可以写成: 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; 或也可以通过其他方法实现。
select col1,col2 from mytable group by col1,col2;这样行吗,效率方面是不是差了
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
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;
或也可以通过其他方法实现。