码迷,mamicode.com
首页 > 数据库 > 详细

row_number() over 两表连接分页SQL

时间:2014-09-11 17:20:52      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:row_number over   两表连接分页   row_number over 不排序   

--总条数
SELECT COUNT(1)
FROM  dbo.osaleh   INNER JOIN dbo.osaled 
ON dbo.osaleh.osaleh_osalehID=dbo.osaled.osaled_osalehID WHERE 
--两表连接分页
SELECT * FROM(
	SELECT ROW_NUMBER() OVER ( ORDER BY osaleh_osalehID DESC ) AS rownum,
	dbo.osaleh.osaleh_osalehID,
	dbo.osaleh.osaleh_custname,
	dbo.osaleh.osaleh_tel,
	dbo.osaleh.osaleh_Name,
	dbo.osaleh.osaleh_userID,
	(SELECT User_LastName FROM dbo.Users (NOLOCK) WHERE User_UserId=dbo.osaleh.osaleh_userID) AS SalesManName,
	dbo.osaleh.osaleh_mkdate,
	dbo.osaled.osaled_oactvhID
	FROM  dbo.osaleh   INNER JOIN dbo.osaled   
	ON dbo.osaleh.osaleh_osalehID=dbo.osaled.osaled_osalehID
	WHERE dbo.osaled.osaled_oactvhID=2
) AS tb WHERE rownum BETWEEN( (1 - 1) *5+1) AND ( 1 * 5 )

--如果不排序
SELECT * FROM(
	SELECT ROW_NUMBER() OVER ( ORDER BY (SELECT 0) ) AS rownum,
	dbo.osaleh.osaleh_osalehID,
	dbo.osaleh.osaleh_custname,
	dbo.osaleh.osaleh_tel,
	dbo.osaleh.osaleh_Name,
	dbo.osaleh.osaleh_userID,
	(SELECT User_LastName FROM dbo.Users (NOLOCK) WHERE User_UserId=dbo.osaleh.osaleh_userID) AS SalesManName,
	dbo.osaleh.osaleh_mkdate,
	dbo.osaled.osaled_oactvhID
	FROM  dbo.osaleh   INNER JOIN dbo.osaled   
	ON dbo.osaleh.osaleh_osalehID=dbo.osaled.osaled_osalehID
	WHERE dbo.osaled.osaled_oactvhID=2
) AS tb WHERE rownum BETWEEN( (1 - 1) *5+1) AND ( 1 * 5 )

row_number() over 两表连接分页SQL

标签:row_number over   两表连接分页   row_number over 不排序   

原文地址:http://blog.csdn.net/chinaplan/article/details/39207711

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!