Description:
How do you label each row, like Pass or Fail? CASE WHEN - the if-else of SQL.
Syntax:
CASE WHEN condition
THEN value
ELSE other_value
END AS new_column
Example (pass mark is 50):
SELECT name,
CASE WHEN score >= 50
THEN 'Pass' ELSE 'Fail'
END AS result
FROM marks;
Don't forget END - every CASE needs one!
SQL in 60 Seconds - one concept a day. Follow The Data Builder!
#sql #learnsql #casewhen #database #dataanalytics #coding #shorts
Share this link via
Or copy link























