SQL Server中前5行之前的行 [英] Rows Prior to Top 5 rows in Sql Server
本文介绍了SQL Server中前5行之前的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从表格中返回最后插入的五行之前的行...
我该怎么办...
我只知道获得前五行,但是现在我想将行插入到前五行之前.
I want to return the rows from my table prior to last five inserted rows...
How can i do this...
I only know to get the top five rows but now i want to get the rows inserted before the top five rows.
推荐答案
假设您的tablename
具有主键用pid
的名称:
Assuming yourtablename
has a primary key by the name ofpid
:
select * from tablename where pid not in (select top 5 pid from tablename order by pid desc)
尝试一下
Try this
with tmp as(
select color, row_number() over (partition by date order by date) rn
from TableA
)
select * from tmp where rn > 5
这篇关于SQL Server中前5行之前的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文