1 select row_number() over(order by StudentNo ) 2 from Student 3 ---第一种分页原理:要查第三页 先将前三页的记录全部查出来 再在 4 ---这个结果集的基础上再进行一次子查询 将结果倒序并且取 5 ---前10条 6 select top 10 * from (select Top 30 * from Student 7 order by StudentNo ASC )as t order by t.StudentNo desc 8 ---子查询 将子查询的结果作为条件来过滤 9 ---第二种分页 要查询第二页 那么久将第一页的id取出来 10 ---然后再取出所有的不在第一页的id 再取前10条 11 select top 10 * from Student 12 select top 10 * from Student where StudentNo not in 13 (select top 20 StudentNo from Student) 14 ---子查询 1、当作查询的数据源 (查询的结果集)要给结果集 15 ---取一个别名 16 ---2、作为条件 当作为=、〉=等后面 查询的值必须唯一 否则用in等 17 18 ---推荐的分页 19 select * from 20 (select row_number() over(order by StudentNo ) as id,* from 21 Student) as newTemp where newTemp.id between (5-1)*10+1 and 5*10 22 23 ---any相当于or 24 select top 10 * from Student where StudentNo> any 25 (select 2 union select 3) 26 ---all相当于and 27 select top 10 * from Student where StudentNo> all 28 (select 2 union select 3) 29 30 ----连接查询 将多个表按照一定的条件连接在一起形成一个结果集 31 32 ----innner join 两边都匹配才会出现在结果集中 33 select * from Student inner join Result 34 on Student.StudentNo=Result.StudentNo