En uzun boşluk
Evanston 311 taleplerinin gönderilmesi arasındaki en uzun süre nedir?
lead() ve lag() için sözdizimini hatırla:
lag(column_to_adjust) OVER (ORDER BY ordering_column)
lead(column_to_adjust) OVER (ORDER BY ordering_column)
Bu egzersiz
SQL ile Keşifsel Veri Analizi
kursunun bir parçasıdırEgzersiz talimatları
- Uygun şekilde
lead()veyalag()kullanarakdate_createdile önceki talebindate_createddeğerini seç. - Her talep ile bir önceki talep arasındaki boşluğu (farkı) hesapla.
- En büyük boşluğa sahip satırı seç.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
-- 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);