Yes, MySQL allows the use of CASE expressions in the FROM clause to select specific rows. The syntax is: SELECT ... FROM table_name WHERE
AND CASE WHEN THEN ; when >THEN ELSE END AS , where
#MySQL FROM Can I use CASE expression later?
Answer:Yes
Detailed explanation:
MySQL allows use in the FROM clause CASE expression to select specific rows from a table. A CASE expression is essentially a conditional statement that can return different values based on given conditions.Syntax:
SELECT ... FROM table_name WHERE AND CASE WHEN THEN WHEN THEN ELSE END AS
is required before applying the CASE expression conditions met.
and
are the conditions to be evaluated.
is the value returned based on the condition.
is the default value returned if no condition is matched.
is the alias assigned to the result of the CASE expression.
Example:
Suppose there is a "customers" table with the following columns:
SELECT * FROM customers WHERE country = 'United States' AND CASE WHEN age > 18 THEN 'Adult' WHEN age <= 18 THEN 'Minor' ELSE 'Unknown' END AS `age_group`;
The above is the detailed content of Can from be followed by case in mysql?. For more information, please follow other related articles on the PHP Chinese website!