此方法需要sql 2005之后能使用
使用分析函数 row_number() over (partiion by ... order by ...)来进行分组编号,然后取分组标号值为1的记录
select s.* from (
select *, rownumber() over (partiion by 分组字段 order by 排序字段) as group_idx from 表名) s where s.group_idx = 1
此方法需要sql 2005之后能使用
使用分析函数 row_number() over (partiion by ... order by ...)来进行分组编号,然后取分组标号值为1的记录
select s.* from (
select *, rownumber() over (partiion by 分组字段 order by 排序字段) as group_idx from 表名) s where s.group_idx = 1