--簡單case函式2.1 select case when 用法case ***
when '1' then '男'
when '2' then '女'
else '其他' end
--case搜尋函式
case
when *** = '1' then '男'
when *** = '2' then '女'
else '其他' end
select grade, count (case when *** = 1 then 1 /**** 1為男生,2位女生*/2.3 where case when 用法else null
end) 男生數,
count (case when *** = 2 then 1
else null
end) 女生數
from students group by grade;
select t2.*, t1.*2.4 group by case when 用法from t1, t2
where (case when t2.compare_type = 'a' and
t1.some_type like 'nothing%'
then 1
when t2.compare_type != 'a' and
t1.some_type not like 'nothing%'
then 1
else 0
end) = 1
select3.1 decode() 函式case when salary <= 500 then '1'
when salary > 500 and salary <= 600 then '2'
when salary > 600 and salary <= 800 then '3'
when salary > 800 and salary <= 1000 then '4'
else null end salary_class, --別名命名
count(*)
from table_a
group by
case when salary <= 500 then '1'
when salary > 500 and salary <= 600 then '2'
when salary > 600 and salary <= 800 then '3'
when salary > 800 and salary <= 1000 then '4'
else null end;
select decode(***, 'm', 'male', 'f', 'female', 'unknown')貌似只有oracle提供該函式,而且不支援ansi sql,語法上也沒case when清晰,個人不推薦使用。from employees;
3.2 在where中特殊實現
select t2.*, t1.*這種方法也是在特殊情況下使用,要多注意邏輯,不要弄錯。from t1, t2
where (t2.compare_type = 'a' and t1.some_type like 'nothing%')
or(t2.compare_type != 'a' and t1.some_type not like 'nothing%')
Oracle CASE WHEN 用法介紹
簡單case函式 case when 1 then 男 when 2 then 女 else 其他 end case搜尋函式 case when 1 then 男 when 2 then 女 else 其他 end 2.1 select case when 用法 select grade,count...
Oracle CASE WHEN 用法介紹
簡單case函式 case when 1 then 男 when 2 then 女 else 其他 end case搜尋函式 case when 1 then 男 when 2 then 女 else 其他 end 2.1 select case when 用法 select grade,count...
Oracle CASE WHEN 用法介紹
簡單case函式 case when 1 then 男 when 2 then 女 else 其他 end case搜尋函式 case when 1 then 男 when 2 then 女 else 其他 end 2.1 select case when 用法 select grade,count...