Difference between revisions of "CASE"
From SQLZOO
| Line 9: | Line 9: | ||
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr> | <tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr> | ||
</table> | </table> | ||
| − | < | + | <h1>CASE</h1> |
<p>CASE allows you to return different values under different conditions. </p> | <p>CASE allows you to return different values under different conditions. </p> | ||
<p>If there no conditions match (and there is not ELSE) then NULL is returned.</p> | <p>If there no conditions match (and there is not ELSE) then NULL is returned.</p> | ||
Revision as of 10:56, 13 July 2012
| CASE WHEN b1 THEN v1 END | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | Yes | |
| mysql | Yes | |
| oracle | Yes | |
| postgres | Yes | |
| sqlserver | Yes | |
CASE
CASE allows you to return different values under different conditions.
If there no conditions match (and there is not ELSE) then NULL is returned.
CASE WHEN condition1 THEN value1
WHEN condition2 THEN value2
ELSE def_value
END
SELECT name, population ,CASE WHEN population<1000000 THEN 'small' WHEN population<10000000 THEN 'medium' ELSE 'large' END FROM bbc
See also