Last active
January 14, 2022 18:16
-
-
Save Mr--John-Doe/633608fefc6a90105aac6f321bed9624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH prep AS ( | |
SELECT * | |
, LAG(accident_ts) OVER (PARTITION BY severity ORDER BY accident_ts) AS previous_accident_ts | |
, DATEDIFF(HOUR, previous_accident_ts, accident_ts) AS time_between_accidents | |
FROM temp.CAMBRIDGESHIRE_ACCIDENTS | |
) | |
SELECT severity | |
, AVG(time_between_accidents) AS avg_time_between_accidents_by_severity | |
FROM prep | |
GROUP BY severity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment