chekos / RIPA-2018-datasette

Publishing datasette of CA's RIPA 2018 data
http://ripa-2018.datasettes.cimarron.io/
GNU General Public License v3.0
0 stars 0 forks source link

Query suggestion #32

Closed chekos closed 4 years ago

chekos commented 4 years ago

Stops within civil twilight by agency

query

SELECT
  AGENCY_NAME,
  IN_TWILIGHT,
  COUNT(*) as N
FROM
  (
    SELECT
      main.UNIQUE_ID,
      main.AGENCY_NAME,
      main.DATE_OF_STOP,
      main.CLOSEST_CITY,
      TIME_OF_STOP,
      twilight.CTWILIGHT_BEGIN as twilight_begin,
      twilight.CTWILIGHT_END as twilight_end,
      CASE
        WHEN TIME_OF_STOP > twilight.CTWILIGHT_BEGIN
        AND TIME_OF_STOP < twilight.CTWILIGHT_END THEN "Within civil twilight"
        ELSE "in the dark..."
      END as IN_TWILIGHT
    FROM
      aa_main_table as main
      INNER JOIN civil_twilight_hours as twilight ON twilight.DATE_OF_STOP = main.DATE_OF_STOP
      AND twilight.CLOSEST_CITY = main.CLOSEST_CITY
  )
GROUP BY 
  AGENCY_NAME, IN_TWILIGHT
chekos commented 4 years ago

Closed with #31 too