Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query suggestion #33

Closed
chekos opened this issue Jul 8, 2020 · 1 comment
Closed

Query suggestion #33

chekos opened this issue Jul 8, 2020 · 1 comment
Assignees
Labels
duplicate This issue or pull request already exists suggestion A canned query suggestion (to be included by default in future deployment)

Comments

@chekos
Copy link
Owner

chekos commented Jul 8, 2020

Stops within by agency by race by whether or not within civil twilight

query

SELECT
  AGENCY_NAME,
  IN_TWILIGHT,
  RACE_ETHNICITY,
  COUNT(*) as N
FROM
  (
    SELECT
      main.UNIQUE_ID,
      main.AGENCY_NAME,
      main.DATE_OF_STOP,
      main.CLOSEST_CITY,
      racen_codes.RACE_ETHNICITY,
      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
      INNER JOIN race_ethnicity as racen ON racen.UNIQUE_ID = main.UNIQUE_ID
      INNER JOIN race_ethnicity_codes as racen_codes ON racen_codes.CODE = racen.RAE_FULL
  )
GROUP BY 
  AGENCY_NAME, RACE_ETHNICITY, IN_TWILIGHT
@chekos chekos added the suggestion A canned query suggestion (to be included by default in future deployment) label Jul 8, 2020
@chekos chekos self-assigned this Jul 8, 2020
@chekos chekos added the duplicate This issue or pull request already exists label Jul 8, 2020
@chekos
Copy link
Owner Author

chekos commented Jul 8, 2020

same as #31

@chekos chekos closed this as completed Jul 8, 2020
@chekos chekos mentioned this issue Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists suggestion A canned query suggestion (to be included by default in future deployment)
Projects
None yet
Development

No branches or pull requests

1 participant