oracle數據庫之組函數


組函數也叫聚合函數,用來對一組值進行運算,並且可以返回單個值

常見的組函數:

(1)count(*),count(列名)  統計行數找到所有不為 null 的數據來統計行數

(2)avg(列名)  平均數

(3)sum(列名)  求和

(4)max(列名)  求最大值

(5)min(列名)  求最小值

scottoracle中的一個示范用戶,主要用於測試。它自帶一些測試用的數據方便我們測試,由於是oracle中的一個對象,因此scott.emp表示數據庫中的員工表。

-- 首先,查看emp 中的所有數據。

select * from scott.emp;

 

--1統計 emp 表中的總行數

select count(*) from scott.emp;

 

 

--統計 emp 表中屬性列為ename的總行數

select count(ename) from scott.emp;

 

 

--統計 emp 表中屬性列為comm的總行數,由於有10項為空,所以行數為4

select count(comm) from scott.emp;

 

 

--2平均值

-- 統計 emp 表中屬性列為comm平均獎金。

-- 一般做法,平均獎金 = 總獎金/總員工數。

select sum(comm) / count(comm) from scott.emp;

-- 使用 avg() 求均值

select avg(sal) from scott.emp;

 

 

--3)使用sum() 求和

select sum(sal) from scott.emp;

 

 

--4最大

select max(sal) from scott.emp;

 

 

--5最小值

select min(sal) from scott.emp;

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM