What's the easiest way to combine a few columns of a table to set up variables for another query?
I want to avoid constantly repeating the same if then statements in my query
SELECT
CASE
WHEN team_id = away_team_id THEN away_score * 5
WHEN team_id = home_team_id THEN home_score * 5
END AS team_score_times_five,
CASE
WHEN team_id = away_team_id THEN away_score - 5
WHEN team_id = home_team_id THEN home_score - 5
END AS team_score_minus_five
FROM t1
Instead I would rather set up one variable
CASE
WHEN team_id = away_team_id THEN away_score
WHEN team_id = home_team_id THEN home_score
END AS team_score
and then query it much more cleanly
SELECT team_score * 5 AS team_score_times_five, team_score - 5 AS team_score_minus_five FROM t1