Skip to content

Instantly share code, notes, and snippets.

@Mr--John-Doe
Last active January 14, 2022 17:56
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 Mr--John-Doe/4cdc80c02da1e492a5dd36e3f8c41593 to your computer and use it in GitHub Desktop.
Save Mr--John-Doe/4cdc80c02da1e492a5dd36e3f8c41593 to your computer and use it in GitHub Desktop.
WindowFunctions-QueryA-NoWindowFunc
SELECT row_level.DATE AS date
, row_level.police_ref AS police_ref
, row_level.casualties AS casualties
, agg.day_total_casualties AS day_total_casualties
, row_level.casualties / agg.day_total_casualties AS casualties_percent_of_day
FROM temp.CAMBRIDGESHIRE_ACCIDENTS row_level
INNER JOIN (SELECT date, SUM(casualties) AS day_total_casualties
FROM temp.CAMBRIDGESHIRE_ACCIDENTS
GROUP BY DATE) agg
ON row_level.date = agg.date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment