oracle分組函數____靜態函數

來源:互聯網
上載者:User

max min avg count sum
1,整個結果集是一個組
   1) 求部門30 的最高工資,最低工資,平均工資,總人數,有工作的人數,工種數量及工資總和 複製代碼 代碼如下:
     select max(ename),max(sal), 
     min(ename),min(sal),
     avg(sal),
     count(*) ,count(job),count(distinct(job)) ,
     sum(sal) from emp where deptno=30;


2, 帶group by 和 having 的分組
   1)按部門分組求最高工資,最低工資,總人數,有工作的人數,工種數量及工資總和 複製代碼 代碼如下:     
    select deptno, max(ename),max(sal),
    min(ename),min(sal),
    avg(sal),
    count(*) ,count(job),count(distinct(job)) ,
    sum(sal) from emp group by deptno;

   
   2)部門30的最高工資,最低工資,總人數,有工作的人數,工種數量及工資總和 複製代碼 代碼如下:     
    select deptno, max(ename),max(sal),
    min(ename),min(sal),
    avg(sal),
    count(*) ,count(job),count(distinct(job)) ,
    sum(sal) from emp group by deptno having deptno=30;

   
3, stddev 返回一組值的標準差
    select deptno,stddev(sal) from emp group by deptno;
    variance 返回一組值的方差差
    select deptno,variance(sal) from emp group by deptno;

4, 帶有rollup和cube操作符的Group By
    rollup 按分組的第一個列進行統計和最後的小計
    cube 按分組的所有列的進行統計和最後的小計
    select deptno,job ,sum(sal) from emp group by deptno,job;
    select deptno,job ,sum(sal) from emp group by rollup(deptno,job); 
    cube 產生組內所有列的統計和最後的小計
    select deptno,job ,sum(sal) from emp group by cube(deptno,job);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.