Skip to content

Instantly share code, notes, and snippets.

@Mr--John-Doe
Last active January 14, 2022 17:58
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/fb0aca8d1182760363e2c14f33f9d198 to your computer and use it in GitHub Desktop.
Save Mr--John-Doe/fb0aca8d1182760363e2c14f33f9d198 to your computer and use it in GitHub Desktop.
WindowFunctions-QueryA-WithWindowFunc
SELECT DATE AS DATE
, police_ref AS police_ref
, casualties AS casualties
, SUM(casualties) OVER (PARTITION BY DATE) AS day_total_casualties
, casualties / day_total_casualties AS casualties_percent_of_day --using lateral alias: day_total_casualties
FROM temp.CAMBRIDGESHIRE_ACCIDENTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment