Maison  >  Article  >  base de données  >  T—SQL用法剪辑,方便以后查看

T—SQL用法剪辑,方便以后查看

WBOY
WBOYoriginal
2016-06-07 17:37:121180parcourir

一、用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;

其结果如图

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent: 游戏数据库部署脚本Article suivant:求SQL语句递归的算法