SQL查询字段有重复只取一条数据

sql查询数据,其中一个字段的数据有重复,重复的数据其他字段除创建时间外都相同,重复数据如何只显示最新的那条数据?

select * from t where 时间 in (
select max(时间) from table group by 相同字段1,相同字段2,相同字段3,....
)

思路 : 查询字段相同的数据(group by 或 distinct) 然后取出时间最新 (max 或者 时间升序)的数据, 将以上结果放在临时表 然后再查询时间存在于临时表的数据,查询出来的结果就是你需要的数据。

;
with tbSource as (
select row_number()over( partition by name,sex,age order by id desc)_row,* from tb_1
)select * from tbSource
where _row = 1
根据name,sex,age这三个列判断重复内容(第二条数据的这三个列的值与第一条完全一致即判重复)

Max(日期),选出这个条件数据,配合group by

select * from table where 相同字段 in (select distinct 相同字段 from table ) and rownum=1