GithubHelp home page GithubHelp logo

2016-nicar-adv-sql's Introduction

2016-NICAR-Adv-SQL

The queries and data for an Advanced SQL class at the NICAR 2016 conference.

This is a slightly modified version of the Advanced SQL class Liz Lucas taught at NICAR 2015. We're going to be using SQLite instead of MySQL. We're also going to use a free Firefox plugin that makes it easier to use SQLite on your computer. It should already be on the classroom computers, but you can also download it here.

All the SQL for the class is in this file: SQL_queries.md

We're going to use inspection data from the Department of Labor/Occupational Safety and Health Administration.

Here's the description from DOL's website: "The dataset consists of inspection case detail for approximately 100,000 OSHA inspections conducted annually. The dataset includes information regarding the impetus for conducting the inspection, and details on citations and penalty assessments resulting from violations of OSHA standards. Additionally, accident investigation information is provided, including textual descriptions of the accident, and details regarding the injuries and fatalities which occurred."

inspection, accident, accident_injury were downloaded from the DOL's site on 02/11/2016.

For this class, I limited the data to Jan 1, 2011 through December 31, 2015.

Record layouts:

What we'll cover:

  • Truthing data tables and joins
  • DISTINCT
  • CREATE TABLE
  • ALTER TABLE to add columns
  • UPDATE to populate new columns
  • Dealing with dates in SQLite (strftime)
  • How to calculate difference in days between two dates
  • Wildcards for more complex filtering
  • Aliases in table names
  • Subqueries

2016-nicar-adv-sql's People

Contributors

taggartk avatar

Stargazers

 avatar Martín González Gómez avatar  avatar Dan Nguyen avatar

Watchers

 avatar

Forkers

jiayuans

2016-nicar-adv-sql's Issues

add count distinct

SELECT count (DISTINCT activity_nr)
FROM osha_inspection_2011_2015_test4

Tell class about the record that was messing up importing into SQLite

SQLite failed to import

Notes — I was getting an error on this row because of the ‘R’ House
300753688,950615,,'R' HOUSE,540 MIDDLE RINCON ROAD,SANTA ROSA,CA,95409.0,A,0.0,N,S,8211.0,611110.0,A,B,,N,,,,,,,,PO BOX 2587,SANTA ROSA,CA,95405.0,N055 000020269,88.0,2011-07-29,2012-12-27,2011-10-05,2012-11-23,2012-12-30 04:29:49.429856,2011-07-29

Opened in Komodo and took out the apostrophes

SELECT *
FROM inspection
WHERE activity_nr = '300753688'

question about OSHA data

Most recent event date in accident table appears to be 2014-01-21 (whereas inspections run through 2015). Ask someone more familiar with OSHA data if this kind of lag is common,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.