進階函數-case

來源:互聯網
上載者:User

標籤:

case函數 (適合區間,>,<判斷)   case when 判斷運算式 then        when 判斷運算式 then        .....   end   select deptno,count(*) total,   sum(case when sal>=2000 then 1       end) great,   sum(case when sal<2000 then 1       end) least  from emp  where deptno is not null  group by deptno; //統計部門中男人數和女人數 create table j20(  id number(7),  name varchar(20),  sex char(1), --‘M‘或‘F‘  deptno number(7));  select deptno,        sum(decode(sex,‘M‘,1,0)) as male,        sum(decode(sex,‘F‘,1,0)) as female from j20 group by deptno;  select deptno,        sum(case when sex=‘M‘ then 1            else 0 end) as male,        sum(case when sex=‘F‘ then 1            else 0 end) as female from j20 group by deptno; //基於EMP表查詢部門編號,工資1000以內人數, 1000-2000人數,2000以上人數 select deptno,    sum(case when sal<1000 then 1             else 0        end) "1000以內",    sum(case when sal>=1000 and sal<2000 then 1             else 0        end) "1000-2000",    sum(case when sal>=2000 then 1             else 0        end) "2000以上" from emp group by deptno;  //查詢調薪結果,規則:MANAGER漲10%,CLERK漲20%,  其他人漲5% select empno,ename,job,sal,        decode(job,‘MANAGER‘,sal*1.1,                   ‘CLERK‘,sal*1.2,                   sal*1.05) "加薪之後" from emp;

 

進階函數-case

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.