Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/3563851c71cfb4bef59a to your computer and use it in GitHub Desktop.
Save mheadd/3563851c71cfb4bef59a to your computer and use it in GitHub Desktop.
Some URLs that can be used to query NYPD Vehicle Crash Data on CivicData.io

Accidents with the greatest number of persons injured in Manhattan (top 10 in descending order).

http://www.civicdata.io/api/action/datastore_search_sql?sql=SELECT%20*%20from%20%22036fcc27-5b0a-401c-aca5-3de5b90143dc%22%20ORDER%20BY%20%22PersonsInjured%22%20DESC%20LIMIT%2010

Total number of accidents in Queens where a cyclist was injured.

http://www.civicdata.io/api/action/datastore_search_sql?sql=SELECT%20COUNT(*)%20from%20%227d6dd1e8-0f86-48c9-80c4-fd0c88a58b3b%22%20WHERE%20%22CyclistsInjured%22%20%3E%200

Total number of pedestrians killed in accidents in Brooklyn.

http://www.civicdata.io/api/action/datastore_search_sql?sql=SELECT%20SUM(%22PedestrKilled%22)%20AS%20%22Total%20pedestrians%20killed%22%20from%20%22ac4a59ea-bf90-4623-9d41-9046875171b2%22

Number of accidents where contributing factors reported in Brooklyn, by Police Precinct

http://www.civicdata.com/api/action/datastore_search_sql?sql=SELECT%20%22ac4a59ea-bf90-4623-9d41-9046875171b2%22.%22OccurrencePrecinctCode%22%20AS%20%22Precinct%20Code%22,%20COUNT(%22ac4a59ea-bf90-4623-9d41-9046875171b2%22.%22CollisionID%22)%20AS%20%22Num%20Accidents%20where%20factors%20reported%22%20from%20%22ac4a59ea-bf90-4623-9d41-9046875171b2%22,%20%22f5795be2-ac78-4580-b831-3df42842071c%22%20WHERE%20%22ac4a59ea-bf90-4623-9d41-9046875171b2%22.%22CollisionID%22%20=%20%22f5795be2-ac78-4580-b831-3df42842071c%22.%22CollisionID%22%20AND%20%22f5795be2-ac78-4580-b831-3df42842071c%22.%22ContributingFactorCode%22%20IS%20NOT%20NULL%20GROUP%20BY%20%22ac4a59ea-bf90-4623-9d41-9046875171b2%22.%22OccurrencePrecinctCode%22%20ORDER%20BY%20%22Num%20Accidents%20where%20factors%20reported%22%20DESC    
@mheadd
Copy link
Author

mheadd commented May 8, 2014

Note - add a callback parameter to any of these URLs and get back JSONP, so that the results can be used directly in a client-side app.

@mheadd
Copy link
Author

mheadd commented May 8, 2014

Raw SQL for querying across two different data sets - both for Brooklyn - to count up the number of accidents where contributing factors were reported.

SELECT "ac4a59ea-bf90-4623-9d41-9046875171b2"."OccurrencePrecinctCode" AS "Precinct Code", COUNT("ac4a59ea-bf90-4623-9d41-9046875171b2"."CollisionID") AS "Num Accidents where factors reported"
from  "ac4a59ea-bf90-4623-9d41-9046875171b2", "f5795be2-ac78-4580-b831-3df42842071c"
WHERE "ac4a59ea-bf90-4623-9d41-9046875171b2"."CollisionID" = "f5795be2-ac78-4580-b831-3df42842071c"."CollisionID"
AND "f5795be2-ac78-4580-b831-3df42842071c"."ContributingFactorCode" IS NOT NULL
GROUP BY "ac4a59ea-bf90-4623-9d41-9046875171b2"."OccurrencePrecinctCode"
ORDER BY "Num Accidents where factors reported" DESC

To run this query against CivicData.io, click here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment