最长间隔
Evanston 的 311 请求在提交时间之间,最长的间隔是多少?
回顾 lead() 和 lag() 的语法:
lag(column_to_adjust) OVER (ORDER BY ordering_column)
lead(column_to_adjust) OVER (ORDER BY ordering_column)
本练习是课程的一部分
SQL 中的探索性数据分析
练习说明
- 使用合适的
lead()或lag(),选出date_created以及上一条请求的date_created。 - 计算每条请求与上一条请求之间的时间间隔。
- 选出间隔最大的那一行。
交互式实操练习
通过完成这段示例代码来试试这个练习。
-- Compute the gaps
WITH request_gaps AS (
SELECT date_created,
-- lead or lag
___(date_created) OVER (___) AS previous,
-- compute gap as date_created minus lead or lag
date_created - ___(date_created) OVER (___) AS gap
FROM evanston311)
-- Select the row with the maximum gap
SELECT *
FROM request_gaps
-- Subquery to select maximum gap from request_gaps
WHERE gap = (SELECT ___
FROM request_gaps);