一、用t-sql查询表中第n行到第m行数据的写法示例 假设这里的n=6,m=10则有以下两种写法,qusid可以不连续,如下: select top 5 * from tb_wenti where qusid not in(select top 5 qusid from tb_wenti); select top 5 * from tb_wenti where qusid in(selec
一、用t-sql查询表中第n行到第m行数据的写法示例
假设这里的n=6,,m=10则有以下两种写法,qusid可以不连续,如下:
select top 5 * from tb_wenti where qusid not in(select top 5 qusid from tb_wenti);
select top 5 * from tb_wenti where qusid in(select top 10 qusid from tb_wenti) order by qusid desc;
一般的写法为
select top m-n+1 * from tablename where id not in(select top n-1 id from tablename);
select top m-n+1 * from tablename where id in(select top m id from tablename) order by id desc;
二、从学生表(student)里分别统计男生人数和女生人数(用一条sql语句)
select distinct (select count(*) from student where 性别='男') 男生数,(select count(*) from student where 性别='女') 女生数 from student;
其结果如图
