case when 在语句中不同位置的用法
1、select case when 用法
select grade, count (case when sex = 1 then 1 /*sex 1为男生,2位女生*/ else null end) 男生数, count (case when sex = 2 then 1 else null end) 女生数 from students group by grade;
2、where case when 用法
select t2.*, t1.* 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
3、group by case when 用法
select 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;
推荐教程:mysql教程
以上就是oracle case when的用法的详细内容。