Skip to content

Instantly share code, notes, and snippets.

@topher1kenobe
Created September 1, 2013 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topher1kenobe/6403986 to your computer and use it in GitHub Desktop.
Save topher1kenobe/6403986 to your computer and use it in GitHub Desktop.
Conditional SQL in MySQL
SELECT
SUM(
CASE
WHEN `home_school_id`= 42 THEN `away_score`
WHEN `away_school_id`= 42 THEN `home_score`
END
) as points_against
FROM
`games`
WHERE
`season_id` = 12
AND
`sport_id` = 67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment