SQL學(xué)習(xí)筆記四 聚合函數(shù)、排序方法
發(fā)布日期:2022-01-25 11:34 | 文章來(lái)源:源碼中國(guó)
select count (*) from T_Employee
select Max(FSalary) from T_Employee 排序 ASC升序 DESC降序
select * from T_Employee order by Fage 先按年齡降序排列。如果年齡相同,則按薪水升序排列
select * from T_Employee order by FAge DESC,FSalary ASC order by 要放在 where 子句之后 通配符過(guò)濾
通配符過(guò)濾用like
單字符通配符‘_'
多字符通配符‘%'
select * from T_Employee where FName like '_erry' NULL 是不知道的意思,而不是沒(méi)有
用SQL語(yǔ)句查詢(xún)NULL的數(shù)據(jù)不能用=或<> 而用is NULL或者is not NULL
select * from T_Employee where FName is NULL in(23,25)同時(shí)匹配兩個(gè)值。相當(dāng)于 23 or 25 between 20 and 30 匹配介于20到30之間的數(shù) group by分組
select FAge, count(*) from T_Employee
Group by Fage
先把相同的Fage分一組,再統(tǒng)計(jì)每一組的個(gè)數(shù) group by子句要放在where子句之后。如果想取某個(gè)年齡段人數(shù)大于1的,不能用where count(*) > 1 ,因?yàn)榫酆虾瘮?shù)不能放在where子句之后。要用having子句
Having是對(duì)分組后的列進(jìn)行過(guò)濾,能用的列和select中的一樣。如下例中則不能用having Fsalary>2000 只能用where Fsalary>2000
select FAge, count(*) from T_Employee
Group by FAge
having count(*) > 1; 限制結(jié)果集的范圍
select Top 3 * from T_Employee
order by FSalary DESC 從第六名開(kāi)始選3個(gè).2005后可以用Row_Number函數(shù)
select Top 3 * from T_Employee
where FNumber not in(select TOP 5 FNumber from T_Employee order by FSalary DESC)
order by FSalary DESC
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信