Home > Database > Mysql Tutorial > T—SQL用法剪辑,方便以后查看

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

WBOY
Release: 2016-06-07 17:37:12
Original
1239 people have browsed it

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

其结果如图

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template