使用SQL Pivot表进行分页

时间:2018-01-14 14:36:06

标签: sql sql-server pivot-table row-number

我有这个查询:

WITH PageIndex AS 
( SELECT TOP 6  ROW_NUMBER() OVER (ORDER BY UserID) as RowIndex,
* FROM [dbo].[vw_EngProfilePivot] WHERE NeedJob='True' ) SELECT * FROM PageIndex
 WHERE RowIndex > 0 AND RowIndex <= 6

[dbo]。[vw_EngProfilePivot]设计:

SELECT
UserID,
MAX(CASE WHEN PropertyDefinitionID = 49 THEN PropertyValue END) AS Gender, MAX(CASE WHEN PropertyDefinitionID = 52 THEN PropertyValue END) AS City, 
MAX(CASE WHEN PropertyDefinitionID = 59 THEN PropertyValue END) AS EngDegreeID, MAX(CASE WHEN PropertyDefinitionID = 60 THEN PropertyValue END) AS EngMajorID, 
MAX(CASE WHEN PropertyDefinitionID = 57 THEN PropertyValue END) AS NeedJob, MAX(CASE WHEN PropertyDefinitionID = 58 THEN PropertyValue END) AS ExperienceYears
FROM            dbo.UserProfile
GROUP BY UserID
_________________________________________________________________________

现在,第一个脚本返回4行,当我传递的页面大小超过&#34; 4&#34;例如&#34; 6&#34;如果页面大小为4(实际结果 - 4行),则执行时间不到100毫秒需要800毫秒吗?

0 个答案:

没有答案