DISTINCT
目前累計(jì)服務(wù)客戶成百上千,積累了豐富的產(chǎn)品開發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹立企業(yè)形象,為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。創(chuàng)新互聯(lián)公司始終以務(wù)實(shí)、誠信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過對(duì)領(lǐng)先技術(shù)的掌握、對(duì)創(chuàng)意設(shè)計(jì)的研究、對(duì)客戶形象的視覺傳遞、對(duì)應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。
DISTINCT是對(duì)整個(gè)結(jié)果集進(jìn)行數(shù)據(jù)重復(fù)處理的,而不是針對(duì)每一個(gè)列,
因此下面的語句并不會(huì)只保留Fdepartment進(jìn)行重復(fù)值處理:
SELECT DISTINCT FDepartment,FSubCompany
FROM T_Employee
2. GROUP BY
按照年齡進(jìn)行分組統(tǒng)計(jì)各個(gè)年齡段的人數(shù):
SELECT FAge,Count(*) FROM T_Employee GROUP BY Fage
GROUP BY子句必須放到WHERE語句的之后
沒有出現(xiàn)在GROUP BY子句中的列是不能放到SELECT語句后的列名列表中的 (聚合函數(shù)中除外)
錯(cuò)誤:
SELECT FAge,FSalary FROM T_Employee GROUP BY FAge
正確:
SELECT FAge,AVG(FSalary) FROM T_Employee GROUP BY FAge
3.Having
在Where中不能使用聚合函數(shù),必須使用Having,Having要位于Group By之后:
SELECT FAge,COUNT(*) AS 人數(shù) FROM T_Employee
GROUP BY FAge
HAVING COUNT(*)>1
注意Having中不能使用未參與分組的列,Having不能替代where。作用不一樣,Having是對(duì)組進(jìn)行過濾。
4.In
Delete T_Employee where FId in(21,22)
SELECT FAge,FNumber,FName FROM T_Employee
WHERE FAge IN (23,25,28)
范圍值:
SELECT * FROM T_Employee WHERE FAGE>=23 AND FAGE <=27
SELECT * FROM T_Employee WHERE FAGE BETWEEN 23 AND 27
5.ORDER BY 數(shù)據(jù)排序
ORDER BY子句位于SELECT語句的末尾,它允許指定按照一個(gè)列或者多個(gè)列進(jìn)行排序,
還可以指定排序方式是升序(從小到大排列,ASC)還是降序(從大到小排列,DESC)。
按照年齡升序排序所有員工信息的列表:
SELECT * FROM T_Employee ORDER BY FAge ASC
按照年齡從大到小排序,如果年齡相同則按照工資從大到小排序 :
SELECT * FROM T_Employee ORDER BY FAge DESC,FSalary DESC(多個(gè)排序條件)
ORDER BY子句要放到WHERE子句之后 :
SELECT * FROM T_Employee WHERE FAge>23 ORDER BY FAge DESC,FSalary DESC