一、排序查詢
1.關鍵字:order by
2.排序方式:asc 升序,可省略;desc 降序,不可省略
3.注意:order by中的欄位與select中的欄位無關
select empno from emp order by sal;
對同一個欄位進行多次排序,只有第一個排序有效
select empno,sal from emp order by sal,sal desc

二、分組查詢
1.關鍵字:group by
2.聚合函式
(1)sum():求和
(2)max():求最大值
(3)min():求最小值
(4)avg():求平均值
(5)count(*/常量/欄位):統計總數,統計的欄位不能為空,不可能出現空值
性能比較:count(*)<count(欄位)<count(常量)
所有的聚合函式都是針對非空欄位進行的
3.having
having與group by子句聯合使用,用來過濾分組之后的資料
4.若SQL陳述句中含有group by子句,此時select子句僅能出現
(1)group 奴役子句中出現的欄位
(2)聚合函式
(3)常量
示例:如果group by中的欄位,沒有出現在select子句中則會報錯
select ename,sal from emp group by deptno;
--不是group by運算式
5.在SQL陳述句中,select子句中含有聚合函式,但是并沒有出現group by子句的情況,select中不能出現聚合函式和常量以外的欄位,
select ename,count(*) from emp;
--不是單租分組函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/301905.html
標籤:其他
上一篇:ERROR tool.ImportTool: Import failed: java.io.IOException: java.lang.ClassNotFoundException: org.apa
下一篇:開源的物聯網平臺
