sql去重,对于数值相同的字段只取最后一条数据或第一条数据

select * from xxxxxxx where id in (select max(id) from xxxxxxx where  AAAA='0000 '  group by BBBB)

xxxxxxx 为表名

AAAA 为表中的列名(也是该sql语句中的条件列)

BBBB 为有重复数据的列名

max(id) 为取重复数据中id最大的那条数据

如果要取第一条数据,可以用 min(id)

猜你喜欢

转载自blog.csdn.net/dd2016124/article/details/111953404