Oracle SQL CASE COMPLEX複雜用法教學

使用工具sqldeveloper
  請先參考 sqldeveloper下載及安裝及連線

測試資料來源請先參考 Oracle DB 目錄


關鍵詞(keyword): case
複雜 case

case  where 來源 條件 什麼值 then 是的輸出值
 where 來源 條件 什麼值 then 是的輸出值
else 否的輸出值
end "別名"

例:
使用employees

薪水收入等次
低收入 0~4999
中低收入 5000~9999
中收入 10000~14999
中高收入 15000~ 19999
高收入 20000以上

SELECT 
employee_id,
salary,
case when salary between 0 and 4999 then '低收入'
when salary between 5000 and 9999 then '中低收入'
when salary between 10000 and 14999 then '中收入'
when salary between 15000 and 19999 then '中高收入'
else '高收入'
end "薪水收入等次"
FROM employees
WHERE employee_id > 140
order by salary;


測試:






 

 







其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()