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
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
引用URL
http://cgi.blog.roodo.com/trackback/1208991