sqlserver2005分页rownumber模式

sqlserver2005分页rownumber方式
sql语句如下:
select * from (select *, ROW_NUMBER() OVER(Order by a.id DESC ) AS RowNumber from classes as a)b where RowNumber BETWEEN 1 and 5

多表联合查询sql语句如下:
select * from (select *,row_number() over( order by a.xy desc) as RowNumber from (select co.name as xy,sp.name zy,cl.name bj,count(st.classes_id) as zrs,count(case when st.sex = '男' then +1 end) as ns,count(case when st.sex = '女' then +1 end) as nvs,
count(case when st.face = '党员' then +1 end) as dy,count(po.student_id) as gb,count(case when st.nation != '汉族' then +1 end) as mz,
count(case when st.face = '团员' then +1 end) as ty from college co left join Specialty sp on co.id = sp.college_id
left join classes cl on cl.Specialty_id = sp.id left join student st on st.classes_id = cl.id
left join Position po on po.student_id = st.studentid  group by co.name,cl.name,sp.name ) a)b
where RowNumber BETWEEN 1 and 5 order by xy

相关内容推荐