淘寶客為什么做網(wǎng)站東莞疫情最新情況
此篇文章內(nèi)容均來自與mysql必知必會教材,后期有衍生會繼續(xù)更新、補(bǔ)充知識體系結(jié)構(gòu)
文章目錄
- SQL聚集函數(shù)表:
- AGV()
- count()
- 根據(jù)需求可以進(jìn)行組合處理
- max()
- min()
- max()、min()、avg()組合使用匯總數(shù)據(jù)
SQL聚集函數(shù)表:
AGV()
AVG():
1、單列使用AVG();
2、多列求平均值的情況下必須使用多個(gè)agv()
語法:
select avg(列1) as 別名1, avg(列2) 別名2 … from 表;
select avg(e.sal) 平均工資,avg(e.mgr) 平均補(bǔ)助 from emp e
count()
count()統(tǒng)計(jì)總數(shù)值
1、count(*) :返回的結(jié)果包含所有的null值
select count(*) as 表的總量 from emp:返回所有總數(shù)值
2、count(列名):返回結(jié)果不包含null值
select count(列名) as 列值總量 from emp:返回結(jié)果為列名值不為null的所有總數(shù)統(tǒng)計(jì)
3、可以組合使用多個(gè)count()
count(列名1),count(列名2)..... count(列名n)進(jìn)行非null值得數(shù)據(jù)統(tǒng)計(jì)
select count(sal) as 工資不為null的總量 ,count(mgr) as 補(bǔ)助不為null總量 from emp
根據(jù)需求可以進(jìn)行組合處理
max()
max():最大值數(shù)據(jù)匯總
語法:
select max(列1), max(列2).......max(列n) from 表
1、可以進(jìn)行單個(gè)列最大值統(tǒng)計(jì)
select max(sal) as 最高工資 from emp;統(tǒng)計(jì)工資最高值
2、可以進(jìn)行多個(gè)列最大值統(tǒng)計(jì),必須使用多個(gè)max()
select max(sal) as 最高工資, max(mgr) as 最高補(bǔ)助,from emp;統(tǒng)計(jì)多列最高數(shù)據(jù)
min()
min():最小值數(shù)據(jù)匯總
語法:
select min(列1), min(列2).......min(列n) from 表
1、可以進(jìn)行單個(gè)列最大值統(tǒng)計(jì)
select min(sal) as 最低工資 from emp;統(tǒng)計(jì)工資最低值
2、可以進(jìn)行多個(gè)列最小值統(tǒng)計(jì),必須使用多個(gè)min()
select min(sal) as 最低工資, min(mgr) as 最高di助,from emp;統(tǒng)計(jì)多列最高數(shù)據(jù)
max()、min()、avg()組合使用匯總數(shù)據(jù)
組合使用聚合函數(shù)進(jìn)行數(shù)據(jù)匯總
語法:
select max(列1),min(列2),avg(列3) from 表
1、單個(gè)列進(jìn)行組合統(tǒng)計(jì)
select max(sal) as 最高工資,min(sal) 最低工資 ,avg(sal) as 平均工資 from 表
2、多列進(jìn)行組合統(tǒng)計(jì)
select max(sal) as 最高工資,min(mgr) 最低補(bǔ)助 ,avg(comm) as 平均單價(jià)from 表