oracle中case when使用

來源:互聯網
上載者:User

標籤:name   篩選   其它   使用   mgr   --   select   font   scott   

case...when 條件轉換函式        case when有兩種表現形式          1 case 變數 when 值1 then 結果1                          when 值2 then 結果2                  else ‘其它‘ end --else可以選擇不要            樣本:            select ename,job,(                   case job when ‘MANAGER‘ then job                             when ‘CLERK‘   then job end)             from emp;         2 case when 運算式1 then 結果1                 when 運算式2 then 結果2             else ‘其它‘ end             樣本:             select ename,sal,                   case when deptno=10 then ‘會計部‘                         when deptno=20 then ‘研究部‘                        when deptno=30 then ‘銷售部‘             else ‘其它部門‘ end              from emp;--在case when中當前麵條件篩選過後,後面是從前面剩下的資料中再抽取。--以scott使用者下面emp表為例。--在進行第二中方法時需要考慮到順序。SQL> select t.*,case when t.sal>=3000 then ‘[3000‘  2                  when t.sal<3000 and t.sal>=2500 then ‘[2500-3000‘  3                  when t.sal<2500 and t.sal>=1500 then ‘[1500-2500‘  4                  else ‘<1500‘ end as sal_level  5            ,case when t.sal>=3000 then ‘[3000‘  6                  when t.sal>=2500 then ‘[2500-3000‘  7                  when t.sal>=1500 then ‘[1500-2500‘  8                  else ‘<1500‘ end as sal_level_test  9    from emp t;EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO SAL_LEVEL  SAL_LEVEL_TEST----- ---------- --------- ----- ----------- --------- --------- ------ ---------- -------------- 7369 SMITH      CLERK      7902 1980/12/17     800.00               20 <1500      <1500 7499 ALLEN      SALESMAN   7698 1981/2/20     1600.00    300.00     30 [1500-2500 [1500-2500 7521 WARD       SALESMAN   7698 1981/2/22     1250.00    500.00     30 <1500      <1500 7566 JONES      MANAGER    7839 1981/4/2      2975.00               20 [2500-3000 [2500-3000 7654 MARTIN     SALESMAN   7698 1981/9/28     1250.00   1400.00     30 <1500      <1500 7698 BLAKE      MANAGER    7839 1981/5/1      2850.00               30 [2500-3000 [2500-3000 7782 CLARK      MANAGER    7839 1981/6/9      2450.00               10 [1500-2500 [1500-2500 7788 SCOTT      ANALYST    7566 1987/4/19     3000.00               20 [3000      [3000 7839 KING       PRESIDENT       1981/11/17    5000.00               10 [3000      [3000 7844 TURNER     SALESMAN   7698 1981/9/8      1500.00      0.00     30 [1500-2500 [1500-2500 7876 ADAMS      CLERK      7788 1987/5/23     1100.00               20 <1500      <1500 7900 JAMES      CLERK      7698 1981/12/3      950.00               30 <1500      <1500 7902 FORD       ANALYST    7566 1981/12/3     3000.00               20 [3000      [3000 7934 MILLER     CLERK      7782 1982/1/23     1300.00               10 <1500      <1500

 

oracle中case when使用

聯繫我們

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