In SQL, CASE WHEN can be used in the WHERE clause. Used to specify different results when a condition is true or not true, thereby filtering data and selecting only rows that meet specific conditions. The syntax is: WHERE CASE WHEN
THEN WHEN THEN ... ELSE END.
Can CASE WHEN
in the WHERE clause of SQL be used in the WHERE clause? CASE WHEN?
Yes, you can use the CASE WHEN statement in the WHERE clause.
how to use?
The CASE WHEN statement is used to specify different results when a condition is true or not. In the WHERE clause, it can be used to filter data and select only rows that meet certain criteria.
Syntax:
WHERE CASE WHEN THEN WHEN THEN ... ELSE END
Example:
SELECT * FROM table_name WHERE CASE WHEN age > 18 THEN 'Adult' WHEN age BETWEEN 13 AND 18 THEN 'Teen' ELSE 'Child' END;
This query will select all from the table named "table_name" rows and classify them as "Adult", "Teen" or "Child" based on their "age" column.
Note:
The above is the detailed content of Can case when be used after where in sql?. For more information, please follow other related articles on the PHP Chinese website!