方法1:使用distinct

方法2:使用ROW_NUMBER()函数

如:

select * from (select  ROW_NUMBER() over(Partition by name order by ID asc) as rowid,t.*

from t) t1

where t1.rowid=1

解释:

Partition by(根据姓名排重) name order by ID(根据ID排序) asc

此段SQL的意思为。

只取ROWID为1的数据。因为ROWID通过ROW_NUMBER()函数获取的。如果NAME 相同的有几位,

where t1.rowid=1为限定条件,只取第一位。

相关文章:

  • 2021-05-18
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2021-07-19
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
相关资源
相似解决方案