一、用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;
其結果如圖
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com