日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Oracle 数据库-分组函数总结

發布時間:2023/12/10 数据库 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle 数据库-分组函数总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Oracle 分組函數

分組函數作用于一組數據,并對一組函數返回一個值。

組函數類型
avg,count,max,min,sum
可以對數值型數據使用avg和sum函數。

select avg(salary),min(salary),max(salary),sum(salary) from employees where job_id like '%REP%';

avg(平均值)和sum(合計)函數:
可以對任意數據類型的數據使用 min和 max函數(包括日期)。

select min(hire_date),max(hire_date) from employees

count(*)返回表中記錄總數,適用于任意數據類型。

select count(*) from employees where department_id = 50;

count (expr) 返回expr不為空的記錄總數。

select count (commission_pct) from employees where department_id = 50;

組函數忽略空值

select avg(commission_pct) from employees;
·
NVL函數使分組函數無法忽略空值

select avg(nvl(commission_pct,0)) from employees;

count (distinct expr)返回expr非空且不重復的記錄總數

select count(distinct department_id) from employees;

可以使用group by子句將表中的數據分成若干組,在select列表中所有未包含在組函數中的列都應該包含在 group by子句中。

select department_id,avg(salary) from employees group by department_id;

包含在 group by 子句中的列不必包含在select列表中:

select avg(salary) from employees group by department_id;

在group by 子句中包含多個列:

select department_id,job_id,sum(salary) from employees group by department_id,job_id;

非法使用組函數:所有包含于select列表中,而未包含于組函數中的列都
必須包含于 GROUP BY 子句中。
如下:
select department_id,count(last_name) from employees;

非法使用組函數
? 不能在where子句中使用組函數。
? 可以在having子句中使用組函數。

如下:
select department_id,avg(saslary) from employees where avg(salary)>8000 group by department_id;
過濾分組:having 子句

  • 行已經被分組。
  • 使用了組函數。
  • 滿足having子句中條件的分組將被顯示。
  • select department_id,max(salary) from employees group by department_id having max(salary)>10000;

    嵌套組函數

    select max(avg(salary)) from employees group by department_id;

    總結

    以上是生活随笔為你收集整理的Oracle 数据库-分组函数总结的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。