表A:
row_id row_num
3488 1
3488 2
3488 3
4523 1
4523 2
8783 1
9999 2
9999 3
9999 4
如何得到我的表的结果,其中row_num应该大于row_num的最小值? [例如row_num>分钟(ROW_NUM)]
预期结果
row_id row_num
3488 2
3488 3
4523 2
9999 3
9999 4
答案 0 :(得分:1)
使用min()over()
select row_id, row_num
from (
select row_id, row_num, min(row_num) over() rm -- probably add partition by row_id
from myTable
) t
where row_num > rm
答案 1 :(得分:0)
使用ROWNUMBER和分区按RowIds进行分区,然后获得rownum> 1
;with cte
as
(select row_id,row_num,
row_number() over (partition by row_id order by row_num) as rownum
from #temp
)
select row_id,row_num from cte where rownum>1