Skip to content

Instantly share code, notes, and snippets.

@stick
Created July 10, 2012 18:35
Show Gist options
  • Save stick/3085397 to your computer and use it in GitHub Desktop.
Save stick/3085397 to your computer and use it in GitHub Desktop.
query
SELECT
scores.player_id,
ifnull(scores.hole_1 , 0) +
ifnull(scores.hole_2 , 0) +
ifnull(scores.hole_3 , 0) +
ifnull(scores.hole_4 , 0) +
ifnull(scores.hole_5 , 0) +
ifnull(scores.hole_6 , 0) +
ifnull(scores.hole_7 , 0) +
ifnull(scores.hole_8 , 0) +
ifnull(scores.hole_9 , 0) +
ifnull(scores.hole_10, 0) +
ifnull(scores.hole_11, 0) +
ifnull(scores.hole_12, 0) +
ifnull(scores.hole_13, 0) +
ifnull(scores.hole_14, 0) +
ifnull(scores.hole_15, 0) +
ifnull(scores.hole_16, 0) +
ifnull(scores.hole_17, 0) +
ifnull(scores.hole_18, 0) as total,
ifnull(scores.hole_1 , projected_scores.hole_1 ) - projected_scores.hole_1 +
ifnull(scores.hole_2 , projected_scores.hole_2 ) - projected_scores.hole_2 +
ifnull(scores.hole_3 , projected_scores.hole_3 ) - projected_scores.hole_3 +
ifnull(scores.hole_4 , projected_scores.hole_4 ) - projected_scores.hole_4 +
ifnull(scores.hole_5 , projected_scores.hole_5 ) - projected_scores.hole_5 +
ifnull(scores.hole_6 , projected_scores.hole_6 ) - projected_scores.hole_6 +
ifnull(scores.hole_7 , projected_scores.hole_7 ) - projected_scores.hole_7 +
ifnull(scores.hole_8 , projected_scores.hole_8 ) - projected_scores.hole_8 +
ifnull(scores.hole_9 , projected_scores.hole_9 ) - projected_scores.hole_9 +
ifnull(scores.hole_10, projected_scores.hole_10) - projected_scores.hole_10 +
ifnull(scores.hole_11, projected_scores.hole_11) - projected_scores.hole_11 +
ifnull(scores.hole_12, projected_scores.hole_12) - projected_scores.hole_12 +
ifnull(scores.hole_13, projected_scores.hole_13) - projected_scores.hole_13 +
ifnull(scores.hole_14, projected_scores.hole_14) - projected_scores.hole_14 +
ifnull(scores.hole_15, projected_scores.hole_15) - projected_scores.hole_15 +
ifnull(scores.hole_16, projected_scores.hole_16) - projected_scores.hole_16 +
ifnull(scores.hole_17, projected_scores.hole_17) - projected_scores.hole_17 +
ifnull(scores.hole_18, projected_scores.hole_18) - projected_scores.hole_18 as to_par
FROM
scores,
groupings,
projected_scores
WHERE
projected_scores.player_id = scores.player_id
AND scores.grouping_id = groupings.id
AND
scores.id = 352;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment