跳过sql server 2008 r2中的查询结果中的n行 [英] skip n rows in query result in sql server 2008 r2

查看:245
本文介绍了跳过sql server 2008 r2中的查询结果中的n行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将在查询结果中跳过n行。但我不能。请帮帮我。

这是我的查询。



hi
i will skip n rows in my query result. but i cant. please help me.
it is my query.

SELECT DISTINCT  * FROM [tbl_Contents] inner join [tbl_Box_Contents] on [tbl_Box_Contents].[boxID]=1 WHERE  ([tbl_Contents].[Feature] = 'false')  and ([tbl_Contents].[ID]=[tbl_Box_Contents].[newsID]) and ([tbl_Contents].[Approve]='true') ORDER BY [tbl_Contents].[datetimeContent] DESC





例如

以上查询的结果是

1 - - - - - - - -

2 - - - - - - - -

3 - - - - - - - -

4 - - - - - - - -

5 - - - - - - - -

i将跳过前两行

最后结果

3 - - - - - - - -

4 - - - - - - - -

5 - - - - - - - -



for example
the result of above query is
1 -- -- -- -- -- -- -- --
2 -- -- -- -- -- -- -- --
3 -- -- -- -- -- -- -- --
4 -- -- -- -- -- -- -- --
5 -- -- -- -- -- -- -- --
i will skip first two rows
and finally result
3 -- -- -- -- -- -- -- --
4 -- -- -- -- -- -- -- --
5 -- -- -- -- -- -- -- --

推荐答案

Offset Fetch子句:

< br $>


Offset Fetch clause :


SELECT DISTINCT  * FROM [tbl_Contents] inner join [tbl_Box_Contents] on [tbl_Box_Contents].[boxID]=1 WHERE  ([tbl_Contents].[Feature] = 'false')  and ([tbl_Contents].[ID]=[tbl_Box_Contents].[newsID]) and ([tbl_Contents].[Approve]='true') ORDER BY [tbl_Contents].[datetimeContent] DESC OFFSET 2 ROWS;





参考这个

http://technet.microsoft.com/en-us/library/gg699618%28v=sql.110%29.aspx [ ^ ]











Refer this
http://technet.microsoft.com/en-us/library/gg699618%28v=sql.110%29.aspx[^]


or

WITH mytable AS
(
    SELECT

        ROW_NUMBER() OVER (ORDER BY user_id) AS RowNumber,user_code,cloumn2,column2
    FROM
        tbL_user_Registration
)
SELECT
    *
FROM
    mytable
WHERE
    RowNumber >2


也许你想用ROW_NUMBER()函数?
Perhaps you'de like to use the ROW_NUMBER() function?


参考:如何到获得正行起,从排-M-从排序表功能于T-SQL [ ^ ]


这篇关于跳过sql server 2008 r2中的查询结果中的n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆