SQL中的Case用法
[ <<label_name>> ]
CASE { WHEN boolean_expression THEN {statement;} … }…
[ ELSE {statement;}… ]
END CASE [ label_name ];
CASE { WHEN boolean_expression THEN {statement;} … }…
[ ELSE {statement;}… ]
END CASE [ label_name ];
simple_case_statement ::=
[ <<label_name>> ]
CASE case_operand
{ WHEN when_operand THEN {statement;} … }…
[ ELSE {statement;}… ]
END CASE [ label_name ];
'————————————————————————————–
1.select cust_last_name,
CASE credit_limit WHEN 100 THEN 'Low'
WHEN 5000 THEN 'High'
ELSE 'Medium' END
FROM customers;
2.select AVG(CASE WHEN e.salary > 2000 THEN e.salary
ELSE 2000 END) "Average Salary" from employees e;
…
转载请注明 :IT樵客