2006年03月5日

oracle的case的語法

select count(*) total,
sum(decode(to_char(hire_date,'yyyy'),1995,1,0)) "1995",
sum(decode(to_char(hire_date,'yyyy'),1996,1,0)) "1996",
sum(decode(to_char(hire_date,'yyyy'),1997,1,0)) "1997",
sum(decode(to_char(hire_date,'yyyy'),1998,1,0)) "1998"
from employees;


select count(hire_date),
sum(case when to_char(hire_date,'yyyy')='1995' then 1 end ) as "1995",
sum(case when to_char(hire_date,'yyyy')='1996' then 1 end ) as "1996",
sum(case when to_char(hire_date,'yyyy')='1997' then 1 end ) as "1997",
sum(case when to_char(hire_date,'yyyy')='1998' then 1 end ) as "1998"
from employees

 

Posted by my_work at 樂多Roodo! │17:08 │回應(0)引用(0)DB
樂多分類:網路/3C 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/1208991