oracle case when的用法
CASE WHEN 在语句中不同位置的用法
1、SELECT CASE WHEN 用法SELECTgrade, COUNT (CASE WHEN sex = 1 THEN 1/*sex 1为男生,2位女生*/ELSE NULLEND) 男生数,COUNT (CASE WHEN sex = 2 THEN 1ELSE NULLEND) 女生数FROM students GROUP BY grade;2、WHERE CASE WHEN 用法SELECT T2.*, T1.*FROM T1, T2WHERE (CASE WHEN T2.COMPARE_TYPE = 'A' ANDT1.SOME_TYPE LIKE 'NOTHING%'THEN 1WHEN T2.COMPARE_TYPE != 'A' ANDT1.SOME_TYPE NOT LIKE 'NOTHING%'THEN 1ELSE 0END) = 13、GROUP BY CASE WHEN 用法SELECTCASE WHEN salary <= 500 THEN '1'WHEN salary > 500 AND salary <= 600THEN '2'WHEN salary > 600 AND salary <= 800THEN '3'WHEN salary > 800 AND salary <= 1000 THEN '4'ELSE NULL END salary_class, -- 别名命名COUNT(*)FROMTable_AGROUP BYCASE WHEN salary <= 500 THEN '1'WHEN salary > 500 AND salary <= 600THEN '2'WHEN salary > 600 AND salary <= 800THEN '3'WHEN salary > 800 AND salary <= 1000 THEN '4'ELSE NULL END;推荐教程:mysql教程以上就是oracle case when的用法的详细内容,更多请关注小潘博客其它相关文章!