不重复,distinct,row_number() over(partition by),sql 分组查询,组内排序, 组内添加序号 (SQL Server 排序函数 ROW_NUMBER和RANK 用法总结)
1、查询不重复的字段
select distinct name from table
2、查询某个字段不重复的,所有内容
sql根据某一个字段重复只取第一条数据
select s.*
from (
select *, row_number() over (partition by [code_ironladel] order by [time_create] desc) as group_idx
from View_track
) s
where s.group_idx = 1
SQL根据某列或几列分组去重——row_number() over(partition by)的用法