├── .gitignore
├── IRE2016
├── part1
│ ├── data
│ │ ├── contributions.txt
│ │ ├── famous_donors.txt
│ │ └── scripts
│ │ │ └── utility
│ │ │ ├── Gemfile
│ │ │ ├── filter_contribs.rb
│ │ │ └── fix_names.rb
│ ├── images
│ │ ├── create_contributions_table.png
│ │ ├── customize-menu.png
│ │ ├── execute_sql.png
│ │ ├── ff-menu.png
│ │ ├── import.png
│ │ ├── import_icon.png
│ │ ├── new_database.png
│ │ └── new_table.png
│ ├── part1_steps.html
│ └── part1_steps.textile
└── part2
│ ├── data
│ ├── candidates.txt
│ └── contributions.txt
│ ├── images
│ ├── ff-menu.png
│ ├── import_icon.png
│ └── new_database.png
│ └── part2.textile
├── NICAR2015
├── candidates.txt
├── committees.txt
├── contributions.txt
├── images
│ └── create_contributions_table.png
├── part1_steps.textile
└── part2_steps.textile
├── NICAR2016
├── part1
│ ├── data
│ │ ├── .#famous_donors.txt
│ │ ├── contributions.txt
│ │ ├── famous_donors.txt
│ │ └── scripts
│ │ │ └── utility
│ │ │ ├── Gemfile
│ │ │ ├── filter_contribs.rb
│ │ │ └── fix_names.rb
│ ├── images
│ │ ├── create_contributions_table.png
│ │ ├── customize-menu.png
│ │ ├── execute_sql.png
│ │ ├── ff-menu.png
│ │ ├── import.png
│ │ ├── import_icon.png
│ │ ├── new_database.png
│ │ └── new_table.png
│ ├── part1_steps.html
│ └── part1_steps.textile
└── part3
│ ├── data
│ ├── candidates.txt
│ └── contributions.txt
│ ├── images
│ ├── ff-menu.png
│ ├── import_icon.png
│ └── new_database.png
│ ├── part3_steps.html
│ ├── part3_steps.textile
│ └── sql_scripts
│ ├── create_candidates.sql
│ └── create_contributions.sql
├── quick_steps.textile
├── quick_steps2.textile
├── readme.textile
└── tutorial_files
├── candidates.txt
├── contributors.txt
├── contributors_candidates.sqlite
├── contributors_with_candidate_id.txt
├── images
├── BUFFET.png
├── alabama.png
├── alert_aggregate.png
├── amount_by_city_state.png
├── amount_by_state.png
├── and_or_sans_parens.png
├── and_statment.png
├── avg_amt.png
├── between.png
├── browse_and_search.png
├── browse_candidates.png
├── browse_contributors.png
├── buffet_by_id.png
├── city_state.png
├── city_state_by_amount_desc.png
├── concat_city_state.png
├── connect_db.png
├── count_ca.png
├── create_table.png
├── delete_prep.png
├── distinct_state_space.png
├── distinct_zip.png
├── execute_sql.png
├── first_and.png
├── group_by_join.png
├── group_by_join_results.png
├── group_by_left_outer_join.png
├── group_by_without_city.png
├── having_amount_greater.png
├── import.png
├── import_confirm.png
├── import_confirm_rows.png
├── import_contributors.png
├── import_icon.png
├── in.png
├── is_not_null.png
├── last_name_NULL.png
├── lewis_or_null.png
├── like_initial.png
├── max_amount.png
├── multiple_joins.png
├── new_database.png
├── new_table.png
├── not_lewis.png
├── open_sqlite.png
├── or_statement.png
├── order_by.png
├── order_by_desc.png
├── order_by_multiple.png
├── select_all.png
├── select_contributors_candidates_names.png
├── select_distinct.png
├── select_distinct_lname.png
├── select_distinct_state_normal.png
├── select_substr.png
├── self_join.png
├── sqlite_manager_empty.png
├── sqlite_manager_ff.png
├── sqlite_open_last_db.png
├── state_after_update.png
├── state_column.png
├── state_ga.png
├── subquery_max.png
├── sum_ga.png
├── sum_top_20.png
├── tool_menu.jpg
├── top_twenty_contributors.png
├── va_contribs.png
├── warning_aggregate_where.png
├── where_clause1.png
├── where_gt_2300.png
├── where_gt_2300_with_group.png
├── where_plus_having.png
└── zip_LIKE.png
├── part1.textile
├── part2.textile
├── part3.textile
├── part4.textile
├── sql_keywords.rtf
├── sql_keywords.txt
├── sql_tutorial.txt
├── sqlite_install.textile
├── sqlite_keywords.rtf
└── test.sqlite
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | thumbs.db
3 | .DS_Store
--------------------------------------------------------------------------------
/IRE2016/part1/data/contributions.txt:
--------------------------------------------------------------------------------
1 | id|committee_id|entity_type|last_name|first_name|middle_name|city|state|zip_code|employer|occupation|date|amount
2 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-14|200
3 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-28|250
4 | |C00573519|IND|STANFIELD|AMY||FRANKLIN|TN|370675672|SELF-EMPLOYED|ARTIST|2015-03-31|250
5 | |C00573519|IND|STARK|CHERYL|ANN|ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|MARKETING RESEARCH|2015-03-11|500
6 | |C00573519|IND|STARK|FRED||ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|CEO|2015-03-19|1000
7 | |C00573519|IND|STEBBENS|KIM||EVERETT|WA|982011557|WAYA GROUP INC|EXECUTIVE|2015-03-14|250
8 | |C00573519|IND|STEGEMANN|BELINDA||CLINT|TX|798365308|RETIRED|RETIRED|2015-03-28|500
9 | |C00573519|IND|STEIGERWALD|DONALD||ESCONDIDO|CA|920263942|STEIGERWALD DOUGHERTY INC|BUILDING CONTRACTOR|2015-03-04|250
10 | |C00573519|IND|STEINKAMP|JEFFREY||ROCHESTER|VT|057670098|RETIRED|RETIRED|2015-03-31|1500
11 | |C00573519|IND|STENGEL|LINDA||SIOUX FALLS|SD|571058110|RETIRED|RETIRED|2015-03-30|250
12 | |C00573519|IND|STENSETHER|BARBARA|L|TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500
13 | |C00573519|IND|STENSETHER|JOHN||TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500
14 | |C00573519|IND|STEWARDSON|MELINDA||BUFFALO GAP|TX|795082140|WYLIE INDEPENDENT SCHOOL DISTRICT|READING TEACHER|2015-03-31|250
15 | |C00573519|IND|STOCKSTILL|JAMES||PICAYUNE|MS|394665552|RETIRED|RETIRED|2015-03-04|250
16 | |C00573519|IND|STODDARD|CHERYL||FREDERICKSBURG|VA|224052180|ANTHEM|REGIONAL MANAGER|2015-03-31|250
17 | |C00573519|IND|STOKER|RICHARD||MIAMI BEACH|FL|331417401|RETIRED|RETIRED|2015-03-24|300
18 | |C00573519|IND|THORNTON|JOE||DALLAS|TX|752254816|HFF|REAL ESTATE CAPITAL MARKETS|2015-03-05|2700
19 | |C00573519|IND|TIMBLE|JAMES||FRANKLIN GROVE|IL|610319555|RETIRED|RETIRED|2015-03-28|250
20 | |C00573519|IND|TOBB|RONALD||BROOKEVILLE|MD|208333208|BOWLES FLUIDICS|OPERATIONS VP|2015-03-03|250
21 | |C00573519|IND|TOLLAKSON|DARLENE|M|SOUTH WAYNE|WI|535879761|||2015-03-30|400
22 | |C00573519|IND|TOMANN|DON||BUFFALO|MN|553134253|UMC INC.|BUSINESS OWNER/PROFESSIONAL|2015-03-03|250
23 | |C00573519|IND|TORRENCE|DARREN||PENSACOLA|FL|325075234|SELF-EMPLOYED|OWNER|2015-03-18|250
24 | |C00573519|IND|TORRE|THOMAS||CUMMING|GA|300411205|AT&T|ENGINEER|2015-03-23|250
25 | |C00573519|IND|TRAN|VINCENT||CRESCENT CITY|CA|955319576|STATE OF CALIFORNIA|DENTIST|2015-03-04|1000
26 | |C00574624|IND|CHOATE|CHARLIE||BURLESON|TX|760282217|SELF EMPLOYED|SMALL BUSINESS OWNER|2015-03-31|250
27 | |C00574624|IND|CHOR|MARLENE||ANACONDA|MT|597112904|||2015-03-31|500
28 | |C00574624|IND|MACDONALD|LENNA|R|DANIEL ISLAND|SC|294927523|BVCC LLC|ENTREPRENEUR|2015-03-25|1000
29 | |C00574624|IND|MACH|STEVEN|P|HOUSTON|TX|772190630|MACH INDUSTRIAL GROUP LP|VP FINANCE|2015-03-23|2700
30 | |C00574624|IND|MACKEY|WILLIAM||MIAMI|FL|331566023|||2015-03-31|500
31 | |C00574624|IND|MADDOX|MATTHEW|MATT|HOUSTON|TX|770083017|BROTHERS ALVARADO; P.C.|ATTORNEY|2015-03-30|1000
32 | |C00574624|IND|MADSON|RYAN||EL DORADO HILLS|CA|957629665|NA|N/A|2015-03-28|1000
33 | |C00574624|IND|MAGGLOS|LINDA||MALIBU|CA|902653746|HOMEMAKER|HOMEMAKER|2015-03-24|1000
34 | |C00574624|IND|MAGNESS|SOPHIE||HOUSTON|TX|770571814|MAGNESS ORTHODONTICS|DIRECTOR OF MARKETING|2015-03-23|500
35 | |C00574624|IND|MALONEY|THOMAS||HAMPTON BAYS|NY|119462826|SHINNECOCK HARDWARE|OWNER|2015-03-25|1000
36 | |C00574624|IND|MANN|JODI||STUDIO CITY|CA|916043855|GJ SULLIVAN|BROKER|2015-03-24|1000
37 | |C00574624|IND|MANN|KEN||STUDIO CITY|CA|916043855|COVERX|INSURANCE|2015-03-24|1000
38 | |C00574624|IND|MANN|RICHARD|F|PONTE VEDRA BEACH|FL|320824609|RETIRED|RETIRED|2015-03-31|200
39 | |C00574624|IND|MANNING|JOHN|OWEN|AUSTIN|TX|787315848|GREAT POINT CAPITAL|TRADER|2015-03-31|5400
40 | |C00574624|IND|HARDY|LONNIE||SHREVEPORT|LA|711192503|SELF EMPLOYED|CPA|2015-03-23|1000
41 | |C00574624|IND|MARACCHINI|CHRIS||CEDAR HILL|TX|751041003|AMERICAN AIRLINES|PILOT|2015-03-24|1000
42 | |C00574624|IND|MARDIGIAN|DAVID||BLOOMFIELD HILLS|MI|483040934|MCM MANAGEMENT CORPORATION|CEO|2015-03-31|5400
43 | |C00574624|IND|HARDAWAY|MIKE||MCKINNEY|TX|750706221|RAYTHEON COMPANY|TECH WRITER/EDITOR|2015-03-24|500
44 | |C00574624|IND|HARIPRASAD|SATISH||EAST STROUDSBURG|PA|183027984|SELF EMPLOYED|PRINTER|2015-03-24|500
45 | |C00574624|IND|HARPER|JIM||BIRMINGHAM|MI|480091311|RETIRED|RETIRED|2015-03-24|1000
46 | |C00574624|IND|HARRELL|KEITH||MCKINNEY|TX|750717390|BUSINESS OWNER|COUNSELOR/RESTAURANT OWNER|2015-03-25|5400
47 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|5400
48 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|-2700
49 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|2700
50 | |C00458844|IND|IRIZARRY|STEVEN||WASHINGTON|DC|200041008|ROBERTI+WHITE LLC|CONSULTANT|2014-12-22|2500
51 | |C00458844|IND|SIMMONS|ANNETTE|C|DALLAS|TX|752402620|HOMEMAKER|HOMEMAKER|2014-12-17|5000
52 | |C00458844|IND|MANTENA|RAMA|R|JUPITER|FL|334774202|P4 HEALTHCARE|CEO|2014-11-19|5000
53 | |C00458844|IND|REUS|SANDRA||DORAL|FL|331783787|SUNSHINE GASOLINE|EXECUTIVE|2014-12-19|9600
54 | |C00458844|IND|PATTEN|CAROLYN|A|PORT SAINT LUCIE|FL|349863252|UNIVERSITY OF FLORIDA||2015-02-17|250
55 | |C00458844|IND|PETHOKOUKIS|JOHN|MR|WESTERN SPRINGS|IL|605582013|MORGAN STANLEY|FINANCIAL ADVISOR|2015-02-25|1000
56 | |C00458844|IND|PETHOKOUKIS|SARA||WESTERN SPRINGS|IL|605582013|HOMEMAKER|HOMEMAKER|2015-02-25|1000
57 | |C00458844|IND|PLOMARITIS|TITUS|MR|PELHAM|NH|030765003|RETIRED|RETIRED|2015-03-31|1000
58 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|5000
59 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|-2300
60 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|2300
61 | |C00577130|IND|HOLZHAUER|FRED||NOVATO|CA|949471909|METHOD PRODUCTS, PBC|CHEMIST|2015-06-30|250
62 | |C00577130|IND|HONG|PENELOPE||ROCKPORT|TX|783823610|NOT EMPLOYED|RETIRED|2015-06-30|250
63 | |C00577130|IND|WYATT|EDNA||SANTA FE|NM|875012242|SELF-EMPLOYED|CARPENTER|2015-05-20|300
64 | |C00577130|IND|YOUNKIN|RANDY||YOUNGSTOWN|OH|445052563|||2015-05-20|500
65 | |C00577130|IND|SHEWFELT|MATTHEW||LOS ANGELES|CA|900263322|WILSHIRE ESCROW COMPANY|ESCROW OFFICER|2015-06-18|250
66 | |C00577130|IND|ROTHNER|GLENN||PASADENA|CA|911052720|ROTHNER, SEGALL & GREENSTONE|ATTORNEY|2015-06-18|250
67 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400
68 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400
69 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300
70 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300
71 | |C00577130|IND|KAST|RICHARD||BURLINGTON|VT|054082544|SELF-EMPLOYED|PHYSICIAN|2015-06-18|212
72 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200
73 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200
74 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250
75 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250
76 | |C00577130|IND|MCDANIEL|MICHAEL|J|SAN DIEGO|CA|921082806|SELF|MD|2015-06-18|200
77 | |C00577130|IND|ALLEN|BRUCE||LAUGHLIN|NV|890280673|SELF-EMPLOYED|CLINICAL PSYCHOLOGIST|2015-06-02|2700
78 | |C00577130|IND|ALLEN|YOKO||LAUGHLIN|NV|890280673|N/A|HOMEMAKER|2015-06-02|2700
79 | |C00577130|IND|ROBERTSON|JOAN|R|MILWAUKEE|WI|532174340|||2015-06-10|1000
80 | |C00577130|IND|MURRAY|BRIAN||LOS ANGELES|CA|900344551|SHEPPARD MULLIN LLP|ATTORNEY|2015-06-18|250
81 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500
82 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500
83 | |C00577130|IND|PAUL|JANE||LOS ANGELES|CA|900662840|ANTIOCH UNIVERSITY|TEACHER|2015-06-18|250
84 | |C00577130|IND|PRUITT|GRETA||LA CRESCENTA|CA|912141541|NOT EMPLOYED|RETIRED|2015-06-18|250
85 | |C00577130|IND|PULICE|MICHAEL||LOS ANGELES|CA|900683128|HOUSEBLEND MEDIA|PRODUCTION ASSISTANT|2015-06-18|250
86 | |C00580100|IND|ANDALORO|JIM||MARBLEHEAD|MA|01945|METAL TRONICS, INC.|OWNER|2015-06-30|500
87 | |C00580100|IND|ANTON|FRANCINE||SPRING LAKE|MI|49456|RETIRED|RETIRED|2015-06-24|250
88 | |C00580100|IND|ATKINS|LORI||SAN ANTONIO|TX|78231|TEXAS SINUS CENTER|PHYSICIAN ASSISTANT|2015-06-20|250
89 | |C00580100|IND|BINGHAM|RON||JACKSON|TN|38305|EMG CLINIS OF TENNESSEE|MD|2015-06-19|500
90 | |C00580100|IND|BLUE|JAN||HUNTINGTON BEACH|CA|92648|HOAG HEALTH|SENIOR VICE PRESIDENT|2015-06-17|500
91 | |C00580100|IND|BRIDGES|PAMELA||LAUREL|MS|39443|INTERNATIONAL FIRE|PRESIDENT|2015-06-26|250
92 | |C00580100|IND|BYRNES|JECOAH||COLORADO SPRINGS|CO|80920|EMBREE CAPITAL MARKETS GROUP, INC.|SALES|2015-06-16|250
93 | |C00580100|IND|CANNON|WANDA||BEVERLY HILLS|CA|90210|RETIRED|RETIRED|2015-06-16|250
94 | |C00580100|IND|CARRERAS|DENNIS||COCONUT CREEK|FL|33073|BERSTONE PAYMENT SYSTEMS, LLC|CEO|2015-06-17|250
95 | |C00580100|IND|CARTER|SCOTT||LUBBOCK|TX|79407|OTTO'S GRANARY|MANAGER/OWNER|2015-06-19|250
96 | |C00580100|IND|CHAMPION|STEPHAN||DESTIN|FL|32541|AC LEGG|SALES|2015-06-17|250
97 | |C00580100|IND|COOKINGHAM|GAIL||ROCHESTER HILLS|MI|48307|SELF-EMPLOYED|PHYSICIAN|2015-06-30|250
98 | |C00580100|IND|CRAICHY|KINSEY||TAMPA|FL|33601|LIVING FUEL|CEO|2015-06-29|250
99 | |C00580100|IND|CRUME|W|HAYDEN|COLUMBUS|MS|39705|RETIRED|RETIRED|2015-06-16|2700
100 | |C00580100|IND|CRUMPLER|MARK||ASHDOWN|AR|71822|DOMTAR|MECHANIC|2015-06-29|250
101 | |C00580100|IND|CUGINI|CHRISTY||NAPLES|FL|34119|MILLENIUM|PHYSICIAN|2015-06-25|250
102 | |C00580100|IND|MCGEORGE|EDWARD||RICHMOND|VA|23238|MCGEORGE ROLLING HILLS RV|CEO|2015-06-26|2700
103 | |C00580100|IND|MCKAY|THOMAS||AUSTIN|TX|78720|TOM'S WAY INC.|MACHINIST|2015-06-22|250
104 | |C00580100|IND|MCNERNEY|MICHAEL||SAN PEDRO|CA|90731|MCNERNEY'S, INC|FUNERAL SERVICE PROVIDER|2015-06-18|500
105 | |C00580100|IND|MCPHERSON|EDWARD||LOS ANGELES|CA|90057|SELF-EMPLOYED|PHYSICIAN|2015-06-21|250
106 | |C00580100|IND|MORE|MICHAEL||MARLBOROUGH|MA|01752|TJX|INFRASTRUCTURE ENGINEER III|2015-06-25|350
107 | |C00580100|IND|PERSSON|ALFRED||HEMET|CA|92545|CAB CHRISTIAN INC|CEO|2015-06-16|250
108 | |C00580100|IND|NEW|JOSEPH||CARROLLTON|GA|30116|BARNES VAN LINES|CEO|2015-06-17|250
109 | |C00580100|IND|NEWMAN|PAMELA||NEW YORK|NY|10017|AON RISK SERVICES|EXECUTIVE|2015-06-01|2700
110 | |C00580100|IND|NICKELL|JERRY||AUBREY|TX|76227|SELF-EMPLOYED|CONSULTANT|2015-06-29|250
111 | |C00575795|IND|LOMBARDO|MICHAEL||SHERMAN OAKS|CA|914035345|HBO|TELEVISION EXECUTIVE|2015-04-27|2700
112 | |C00575795|IND|STAFFORD|AMANDA||MCLEAN|VA|221021431|N/A|RETIRED|2015-04-28|2700
113 | |C00575795|IND|WHITAKER|DAVID||FAYETTEVILLE|AR|727011611|SELF-EMPLOYED|ATTORNEY|2015-05-07|201
114 | |C00575795|IND|LIM|TIM||WASHINGTON|DC|200094582|PRECISION NETWORK|PRESIDENT|2015-04-12|250
115 | |C00575795|IND|GEIGER|MARC||LOS ANGELES|CA|900691401|WILLIAM MORRIS ENDEAVOR|AGENT / HEAD OF MUSIC|2015-05-01|2700
116 | |C00575795|IND|HAMILTON|JOHN||DALLAS|TX|752143452|AS MANAGEMENT|REAL ESTATE|2015-05-07|2700
117 | |C00575795|IND|WALLER|KATHY||ATLANTA|GA|303271800|THE COCA-COLA COMPANY|CFO|2015-04-28|2700
118 | |C00575795|IND|WINGENS|GARY||LIVINGSTON|NJ|070393424|LOWENSTEIN SANDLER LLP|ATTORNEY|2015-04-17|2700
119 | |C00575795|IND|EDINGTON|PATRICIA||MOBILE|AL|366022006|SELF-EMPLOYED|ANTIQUES APPRAISER|2015-04-13|500
120 | |C00575795|IND|ALFERNESS|JOY||SAN FRANCISCO|CA|941072734|NOT EMPLOYED|HUMANITARIAN|2015-05-02|1700
121 | |C00575795|IND|FLYNN|JOHN||VIENNA|VA|221816131|N/A|RETIRED|2015-05-14|500
122 | |C00575795|IND|KASSAN|ALEX||NEW YORK|NY|10013|ANCHORAGE MEDIA GROUP|PRODUCTION|2015-04-28|2700
123 | |C00575795|IND|SENATORE|BRAD||BOSTON|MA|021162671|SELF-EMPLOYED|FASHION DESIGN|2015-06-30|1000
124 | |C00575795|IND|HELLER TRIPENY|MARY||CORNING|NY|148309481|SELF-EMPLOYED||2015-05-08|2700
125 | |C00575795|IND|FINKEL|JUDITH||HOUSTON|TX|770245404|N/A|RETIRED|2015-06-01|2700
126 | |C00575795|IND|FORD|ARLENE||BALTIMORE|MD|212101526|N/A|RETIRED|2015-06-19|300
127 | |C00575795|IND|NEWMAN|MELISSA||ALEXANDRIA|VA|223142414|CENTURYLINK|ATTORNEY|2015-04-20|1000
128 | |C00575795|IND|CANTU|ALONZO||MCALLEN|TX|785042202|CANTU CONSTRUCTION & DEVELOPMENT|OWNER/DEVELOPER|2015-06-30|2700
129 | |C00575795|IND|HARRIS|MAYA||NEW YORK|NY|100366812|HILLARY FOR AMERICA|SENIOR POLICY ADVISOR|2015-06-30|2700
130 | |C00575795|IND|OTTINGER|BARBARA||PASADENA|CA|911051342|||2015-05-13|250
131 | |C00575795|IND|HAIRSTON|JAMES||NEWARK|NJ|071121708|N/A|RETIRED|2015-04-30|225
132 | |C00575795|IND|ELLISON|CARL||NEW YORK|NY|101281248|N/A|RETIRED|2015-06-23|2700
133 | |C00575795|IND|MARDIROSSIAN|SHANT||KATONAH|NY|105362919|KOHLBERG & CO., LLC|PARTNER AND COO|2015-06-28|2700
134 | |C00575795|IND|RATNER|TAWNY||CLEVELAND HEIGHTS|OH|441063138|||2015-04-26|2700
135 | |C00575795|IND|LINDEN|MARTHA||ANCHORAGE|AK|995073970|OWEN R. BELL, MD, APC|CERTIFIED NURSE MIDWIFE|2015-04-13|250
136 | |C00581876|IND|DEMLER|JOHN||NORTHFIELD|IL|600933117|RETIRED|SALES|2015-09-29|500
137 | |C00581876|IND|HUMPHREY|GORDON||CHICHESTER|NH|032586102|RETIRED|RETIRED|2015-09-29|2700
138 | |C00581876|IND|PELLEGRINO|BOB||CINCINNATI|OH|452433220|RETIRED|INVESTOR|2015-09-29|250
139 | |C00581876|IND|BOND|JAMES|D|FARGO|ND|581047058|COLLINS & COMPANY|EXECUTIVE|2015-09-29|250
140 | |C00581876|IND|PALAFOUTAS|JUDITH||ALEXANDRIA|VA|223144761|GEORGETOWN UNIVERSITY|RESEARCH DIRECTOR|2015-09-29|1000
141 | |C00581876|IND|WINSLOW|CLARK||BELVEDERE TIBURON|CA|949202426|WINSLOW CAPITAL|INVESTMENT MGMT|2015-09-29|1000
142 | |C00581876|IND|YOUNG|STEWART||WASHINGTON|DC|200024489|CORLEY CONSULTING|LOBBYIST|2015-09-29|250
143 | |C00581876|IND|BATTOCLETTI|DAVID||COLUMBUS|OH|432157513|ICE MILLER WHITEBOARD|LOBBYIST|2015-09-29|1000
144 | |C00581876|IND|COLEMAN|GEORGE||FAIRFIELD|CT|068245649|CREDIT SUISSE|BANKER|2015-09-29|500
145 | |C00581876|IND|SWALDO|THEODORE||NORTH CANTON|OH|447208807|RETIRED|RETIRED|2015-09-29|250
146 | |C00581876|IND|OSTERTHALER|ROBERT||VIENNA|VA|221821368|RETIRED|CEO|2015-09-29|900
147 | |C00581876|IND|BERGAN|PHILIP||CHARLESTON|SC|294012403|RETIRED|RETIRED|2015-09-29|500
148 | |C00581876|IND|DUBRAVCIC|STEPHEN||BRONWOOD|GA|398260083|DARKOTECH, INC|MANAGER|2015-08-07|250
149 | |C00581876|IND|BRISTOW|JULIE||CINCINNATI|OH|452083332|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700
150 | |C00581876|IND|WASSERSTROM|ALAN||COLUMBUS|OH|432072167|WASSERSTROM COMPANIES|CEO|2015-08-07|2700
151 | |C00581876|IND|SANDRIDGE|RHONDA|L|WESTFIELD CENTER|OH|442519801|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700
152 | |C00581876|IND|WILSON|RONALD||SOLON|OH|441395077|GENERAL ELECTRIC|GENERAL MANAGER|2015-08-07|500
153 | |C00581876|IND|BRISTOW|WILLIAM|S|CINCINNATI|OH|452083332|JEFF WYLER AUTOMATIVE FAMILY|PRESIDENT|2015-08-07|2700
154 | |C00581876|IND|FETTER|STEVEN||PORT TOWNSEND|WA|983683058|SELF-EMPLOYED|UTILITY CONSULTANT|2015-08-07|2700
155 | |C00581876|IND|BECHTOLD|TIMOTHY||COLUMBUS|OH|432156108|VORYS SATER|LOBBYIST|2015-08-07|500
156 | |C00581876|IND|STEWART|JENNIFER||NEW HOPE|PA|189389246|STUDENT|STUDENT|2015-08-07|250
157 | |C00581876|IND|ELSANT|MARTIN||WOODMERE|NY|115982909|NORTH SHORE HEALTH SYSTEM|RADIOLOGIST|2015-08-07|200
158 | |C00581876|IND|THOMPSON|LUCINA||DALLAS|TX|752303038|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|2700
159 | |C00581876|IND|EARL|SUSAN||COLUMBUS|OH|432061275|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|250
160 | |C00581876|IND|MAUER|VINCENT||CINCINNATI|OH|452443604|BROCK BROWN COD|LAWYER|2015-08-18|250
161 | |C00580399|IND|COHEN|LARRY||NY|NY|100143744|SEVEN BRIDGES ADVISORS|FINANCIAL ADVISOR|2015-08-13|2700
162 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-09-03|859
163 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-08-15|1840
164 | |C00580399|IND|GUREGHIAN|VAHAN|H|GLADWYNE|PA|190351507|CSMI LLC|FOUNDER AND CEO|2015-09-30|2700
165 | |C00580399|IND|PJETERNIKAJ|LILA||SADDLE RIVER|NJ|074583012|||2015-08-04|1350
166 | |C00580399|IND|CONSIDINE|THOMAS||SPRING LAKE|NJ|077622369|GRAVILAUR SOLUTIONS LLC|CONSULTANT|2015-09-29|2700
167 | |C00580399|IND|CONSORTI|JASON||MONROE|NJ|088312242|CSC|IT MANAGER|2015-07-01|500
168 | |C00580399|IND|CONSTABLE|RICHARD||SOUTH ORANGE|NJ|070791141|US ATTORNEY|LAWYER/LEGAL|2015-09-09|1000
169 | |C00580399|IND|CONTI|GINA||NEW PROVIDENCE|NJ|079742117|HOMEMAKER|HOMEMAKER|2015-09-30|2500
170 | |C00580399|IND|CONTI|KURT|G|NEW PROVIDENCE|NJ|079742117|CONTI GROUP|PRESIDENT/CEO|2015-09-30|2500
171 | |C00580399|IND|CONWAY|ARTHUR|W|MAHWAH|NJ|074302040|DIALAMERICA MARKETING INC.|PRESIDENT & CEO|2015-07-16|2700
172 | |C00580399|IND|GIBBONS|MARY|M|BASKING RIDGE|NJ|079204107|ELBERON DEVELOPMENT GROUP ST. CLAIRE'|ADMINISTRATOR/SOCIAL WORKER|2015-08-20|1000
173 | |C00580399|IND|GIBLIN|BRENDON|P|SOUTHBOROUGH|MA|017721706|BRENDON PROPERTIES|DEVELOPER REAL ESTATE|2015-09-08|500
174 | |C00580399|IND|GIDWITZ|CHRISTINA||CHICAGO|IL|606065829|HOUSEWIFE|HOUSEWIFE|2015-09-27|2700
175 | |C00580399|IND|GILFILLAN|CHRISTINE|C|MORRISTOWN|NJ|079607355|THE MCJ AMELIOR FOUNDATION|PRESIDENT|2015-07-02|2700
176 | |C00580399|IND|GILFILLAN|MICHAEL|T|MADISON|NJ|079402751|BRICK CITY SPORTS CAPITAL LLC|INVESTMENTS|2015-07-02|2700
177 | |C00580399|IND|GILMAN|J|PAUL|MENDHAM|NJ|079451205|COVANTA ENERGY|SENIOR VICE PRESIDENT AND CHIEF SUSTAI|2015-07-31|2700
178 | |C00580399|IND|GILMAN|THOMAS||SCOTTSDALE|AZ|852623818|DAIMLERCHRYSLER FINANCIAL SERVICES AME|CEO|2015-07-27|2700
179 | |C00580399|IND|GILMORE|THOMAS|P|ANDOVER|NJ|078214127|GILMORE ELECTRIC INC.|ELECTRICIAN|2015-07-24|2700
180 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700
181 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700
182 | |C00580399|IND|CONSIGLIO|THOMAS||RAMSEY|NJ|074461346|RESOURCE REALTY|SALES|2015-08-03|2700
183 | |C00580399|IND|COLE|BRIAN||OAKLAND|NJ|074362350|COLE MEDICAL INC|VICE PRESIDENT|2015-07-01|2700
184 | |C00579458|IND|VILLARI|DAVID|J|FORT LAUDERDALE|FL|333061906|GIG INS GROUP|BUSINESS OWNER|2015-11-30|250
185 | |C00579458|IND|VIEIRA|SEAN||FAIRFAX|VA|220336226|SJV LLC|PRESIDENT|2015-11-29|1000
186 | |C00579458|IND|VIJAYANAGAR|RAGHAVENDRA||TAMPA|FL|336063573|R VIJAYANAGAR M.D. P.A.|SURGEON|2015-11-20|2000
187 | |C00579458|IND|VILLARREAL|AARON||MCALLEN|TX|785044405|||2015-10-30|2700
188 | |C00579458|IND|VILLAMIZAR|JOHN||ROYAL PALM BEACH|FL|334116107|ADVANCED VISION|OPTICIAN|2015-12-29|375
189 | |C00579458|IND|WARE|BLAKE|BEAKLEY|AMARILLO|TX|791092331|HOMEMAKER|HOMEMAKER|2015-11-19|2000
190 | |C00579458|IND|WARD|JIM||PHOENIX|AZ|850162363|THE PHOENIX SYMPHONY|CEO|2015-10-14|1000
191 | |C00579458|IND|WARD|JOHN|M|DALLAS|TX|752047849|RETIRED|RETIRED|2015-11-09|1000
192 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|4000
193 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|-2000
194 | |C00579458|IND|WAREHAM|KRISTINA||LAKE HIAWATHA|NJ|070342209|PRECISION CASTPARTS CORP|ENGINEER|2015-12-31|1000
195 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|-2700
196 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|2700
197 | |C00579458|IND|MANNING|RALPH|F|MARS|PA|160462633|TUCKER ARENSBERG PC|ATTORNEY|2015-11-10|1000
198 | |C00579458|IND|MANNING|RAMON||HOUSTON|TX|770211611|PARTNERS ENERGY|INVESTOR|2015-10-28|250
199 | |C00579458|IND|MANNING|SAM|BLAGDEN|DALLAS|TX|752195220|SELF-EMPLOYED|INVESTMENTS|2015-11-10|500
200 | |C00579458|IND|MANRIQUE|FRANCISCO||DORAL|FL|331783505|||2015-10-20|500
201 |
--------------------------------------------------------------------------------
/IRE2016/part1/data/famous_donors.txt:
--------------------------------------------------------------------------------
1 | C00575795|A|Q2|P|201509039001608655|15|IND|BUFFETT, WARREN|OMAHA|NE|681313311|BERKSHIRE HATHAWAY|CHAIRMAN|04152015|2700||C51337|1024052|||4090920151249626621
2 | C00577130|N|Q2|P|201507159000153383|15E|IND|RUFFALO, MARK|NEW YORK|NY|100031526|SELF-EMPLOYED|ACTOR|06022015|250|C00401224|VPF7BDV8BV8|1015044||* EARMARKED CONTRIBUTION: SEE BELOW|4071620151247172334
3 | C00458844|A|Q2|G|201510159003030910|22Y|IND|ADELSON, SHELDON|LAS VEGAS|NV|89145|||06122015|2600||GENREF0042|1029436|||4102120151256390199
4 |
--------------------------------------------------------------------------------
/IRE2016/part1/data/scripts/utility/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'people'
--------------------------------------------------------------------------------
/IRE2016/part1/data/scripts/utility/filter_contribs.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'csv'
4 |
5 | committee_ids = []
6 | CSV.foreach('candidates.txt', :headers => true, :col_sep => '|', :quote_char => "\x00") do |row|
7 | committee_ids << row[0]
8 | end
9 |
10 | skips = ['C00577981', 'C00578757', 'C00577312', 'C00575449', 'C00578658']
11 | used = committee_ids - skips
12 |
13 | included = {}
14 | used.each {|id| included[id] = 0}
15 |
16 | CSV.foreach('itcont.txt', :col_sep => '|', :quote_char => "\x00") do |row|
17 | #skip if not a contrib
18 | next if row[5] != '15'
19 | committee_id = row[0]
20 | if used.include? committee_id
21 | if included[committee_id] < 25
22 | puts row.to_csv(:col_sep => '|')
23 | included[committee_id] += 1
24 | else
25 | used.delete committee_id
26 | break if used.length == 0
27 | end
28 | end
29 | end
30 |
31 |
32 | exit
33 | #####
34 | ## Check the number of contributors per candidate
35 | #####
36 | committee_counts = {}
37 | committee_ids.each do |id|
38 | committee_counts[id] = 0
39 | end
40 |
41 |
42 | committee_ids.each do |id|
43 | CSV.foreach('contributors.txt', :col_sep => '|', :quote_char => "\x00") do |row|
44 | committee_counts[id] += 1 if row[0] == id
45 | end
46 | end
47 |
48 | puts committee_counts
49 |
--------------------------------------------------------------------------------
/IRE2016/part1/data/scripts/utility/fix_names.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'csv'
4 | require 'people'
5 |
6 | np = People::NameParser.new(:case_mode => 'upper')
7 | CSV.foreach('contributors.txt', :col_sep => '|', :quote_char => "\x00") do |row|
8 | no_title = row[7].gsub(/ (MR.|MRS.|DR.|MS.)$/, '')
9 | name = np.parse(no_title)
10 | next if name[:last].empty?
11 | date_parts = row[13].match(/(\d\d)(\d\d)(\d\d\d\d)/)
12 | date_string = "#{date_parts[3]}-#{date_parts[1]}-#{date_parts[2]}"
13 | puts [name[:last], name[:first], name[:middle], row[8], row[9], row[10], row[11], row[12], date_string, row[14], row[0]].to_csv(:col_sep => '|', :quote_char => "\x00")
14 | end
15 |
--------------------------------------------------------------------------------
/IRE2016/part1/images/create_contributions_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/create_contributions_table.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/customize-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/customize-menu.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/execute_sql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/execute_sql.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/ff-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/ff-menu.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/import.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/import.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/import_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/import_icon.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/new_database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/new_database.png
--------------------------------------------------------------------------------
/IRE2016/part1/images/new_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part1/images/new_table.png
--------------------------------------------------------------------------------
/IRE2016/part1/part1_steps.html:
--------------------------------------------------------------------------------
1 |
A Quick Introduction to SQL Using SQLite (Just the Steps)
2 | 1. Open Firefox and click on the menu icon:
3 | 
4 | Use the "customize" option to find the SQLite Manager Plugin:
5 | 
6 | You can add it to your menu by dragging or right-click to add it to the toolbar.
7 |
8 | 2. Create a new database called campaign_finance:
9 | 
10 |
11 | 3. Create a new table called contributions (
) and give it the following field definitions:
12 | 
13 |
14 | Inserting data manually (Don't worry, you won't do this often.)
15 | 4. Insert a row of data.
16 | Use the "Execute SQL" tab (it's in the second menu row, under the icons)
17 | 
18 | And paste or type the following statement:
19 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name, city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','BUFFETT','WARREN','','OMAHA','Nebraska','68131','BERKSHIRE HATHAWAY','CHAIRMAN','2015-04-15',2700);
20 |
21 | 5. Insert three more rows (one at a time or all at once)
22 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00577130','IND','RUFFALO','MARK','','NEW YORK','NY','|100031526','SELF-EMPLOYED','ACTOR','2015-06-02',250);
23 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00458844','IND','ADELSON','SHELDON','','LAS VEGAS','NV','89145','','','2015-06-12',2600);
24 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00579458','IND','MANNING','PEYTON MR.','','CLEVELAND','OH','441141717','DENVER BRONCOS','PROFESSIONAL ATHLETE','2015-08-04',2700);
25 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','COPPOLA','SOFIA','','NEW YORK','NY','100130778','SELF-EMPLOYED','DIRECTOR/WRITER/ACTOR','2016-01-22',2700);
26 |
27 | The SELECT statement
28 | 6. Select everything from the contributions table:
29 | SELECT * FROM contributions;
30 | Note the wildcard * character.
31 |
32 | 7. Choose some fields to select:
33 | SELECT city, state FROM contributions;
34 | Note the duplicates; why are they there?
35 |
36 | 8. Get a distinct set of cities and states:
37 | SELECT DISTINCT city, state FROM contributions;
38 |
39 | THE WHERE CLAUSE
40 | 9. Add some conditions to the SELECT:
41 | SELECT * from contributions WHERE state='NY';
42 | Now try playing around with some of the operators:
43 |
44 |
45 |
46 | operator |
47 | description |
48 |
49 |
50 | = |
51 | Equal |
52 |
53 |
54 | <> |
55 | Not equal* |
56 |
57 |
58 | > |
59 | Greater than |
60 |
61 |
62 | < |
63 | Less than |
64 |
65 |
66 | >= |
67 | Greater than or equal |
68 |
69 |
70 | <= |
71 | Less than or equal |
72 |
73 |
74 |
75 | Here are some examples:
76 | SELECT * from contributions WHERE amount > 500;
77 | SELECT * from contributions WHERE amount >= 500;
78 | SELECT last_name from contributions WHERE state <> 'NY';
79 |
80 | 10. Combine conditions with AND or OR:
81 | Find only the big spenders from New York
82 | SELECT * FROM contributions WHERE city = 'NEW YORK' AND amount > 2000;
83 | Find any big spender and anyone from New York
84 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR amount > 2000;
85 |
86 | 11. But watch out for operator precedence
87 | Looking for big spenders from Las Vegas and New York City
88 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR city = 'LAS VEGAS' AND amount > 2000;
89 | How did Mark Ruffalo sneak in there?
90 | Try that again:
91 | SELECT * FROM contributions WHERE (city = 'NEW YORK' OR city = 'LAS VEGAS') AND amount > 2000;
92 |
93 | Pick One: Using BETWEEN
and IN
(NOT IN
)
94 | 11. Find all contributions between $500 and $1000
95 | SELECT * FROM contributions WHERE amount BETWEEN 251 AND 2699;
96 | (Note: this query returns the same results as SELECT * FROM contributors WHERE amount >= 500 AND amount <= 1000;
-- but it's much more readable.)
97 |
98 | 12. Find all contributors from a list of states:
99 | SELECT * from contributions WHERE state IN ('OH', 'NY');
100 | (Note: A compound statement could accomplish this same goal: state = 'OH' OR state = 'NY'
101 | But the IN
syntax makes things much clearer, and it's easier to write.)
102 |
103 | 13. Use NOT IN
to find results where a value is not included in the given set:
104 | SELECT * FROM contributions WHERE state NOT IN ('NY', 'OH');
105 |
106 | Sorting the results
107 | 14. Use ORDER BY to sort:
108 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount;
109 | And reverse the order:
110 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount DESC;
111 | And order by more than one column:
112 | SELECT state, last_name, amount FROM contributions ORDER BY state, amount DESC;
113 |
114 | Limiting the number of rows returned
115 | 15. Return only the top two contributions:
116 | SELECT * FROM contributions ORDER BY amount DESC LIMIT 2;
117 |
118 | Changing values with UPDATE
119 | 16. Check the list of state names again:
120 | SELECT state FROM contributions;
121 | Let's correct Nebraska:
122 | UPDATE contributions SET state = 'NE' WHERE state = 'Nebraska';
123 | And check again:
124 | SELECT DISTINCT state FROM contributions;
125 |
126 | DELETING rows
127 | 17. Let's get rid of a row:
128 | SELECT * FROM contributions WHERE id = 1;
129 | DELETE FROM contributions WHERE id = 1;
130 |
131 | Importing data from a flat file
132 | 18. Import a delimited file:
133 | a. Go to https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt (Or grab it from the conference computer.)
134 | b. Save the file as "contributions.txt" somewhere you can find it (your desktop is a good place).
135 | c. Click the SQLite Manager Import Wizard icon (
).
136 |
137 | - Using the Select File button, browse for the contributions.txt file you just saved.
138 | - Check the "First row contains column names" check box.
139 | - Select Pipe(|) for "Fields separated by"
140 | - For everything else, you can keep the default selections.
141 | - You should have 204 rows of data.
142 |
143 |
--------------------------------------------------------------------------------
/IRE2016/part1/part1_steps.textile:
--------------------------------------------------------------------------------
1 | h2. A Quick Introduction to SQL Using SQLite (Just the Steps)
2 |
3 | 1. Open Firefox and click on the menu icon:
4 |
5 | !./images/ff-menu.png!
6 |
7 | Use the "customize" option to find the SQLite Manager Plugin:
8 |
9 | !./images/customize-menu.png!
10 |
11 | You can add it to your menu by dragging or right-click to add it to the toolbar.
12 |
13 |
14 |
15 | 2. Create a new database called campaign_finance:
16 |
17 | !./images/new_database.png!
18 |
19 |
20 |
21 | 3. Create a new table called contributions (!./images/new_table.png!) and give it the following field definitions:
22 |
23 | !./images/create_contributions_table.png!
24 |
25 |
26 |
27 | h3. Inserting data manually (Don't worry, you won't do this often.)
28 |
29 | 4. Insert a row of data.
30 |
31 | Use the "Execute SQL" tab (it's in the second menu row, under the icons)
32 | !./images/execute_sql.png!
33 |
34 | And paste or type the following statement:
35 |
36 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name, city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','BUFFETT','WARREN','','OMAHA','Nebraska','68131','BERKSHIRE HATHAWAY','CHAIRMAN','2015-04-15',2700);
37 |
38 |
39 |
40 |
41 | 5. Insert three more rows (one at a time or all at once)
42 |
43 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00577130','IND','RUFFALO','MARK','','NEW YORK','NY','|100031526','SELF-EMPLOYED','ACTOR','2015-06-02',250);
44 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00458844','IND','ADELSON','SHELDON','','LAS VEGAS','NV','89145','','','2015-06-12',2600);
45 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00579458','IND','MANNING','PEYTON MR.','','CLEVELAND','OH','441141717','DENVER BRONCOS','PROFESSIONAL ATHLETE','2015-08-04',2700);
46 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','COPPOLA','SOFIA','','NEW YORK','NY','100130778','SELF-EMPLOYED','DIRECTOR/WRITER/ACTOR','2016-01-22',2700);
47 |
48 |
49 |
50 |
51 |
52 | h3. The SELECT statement
53 |
54 | 6. Select everything from the contributions table:
55 |
56 | SELECT * FROM contributions;
57 |
58 | Note the wildcard * character.
59 |
60 |
61 |
62 | 7. Choose some fields to select:
63 |
64 | SELECT city, state FROM contributions;
65 |
66 | Note the duplicates; why are they there?
67 |
68 |
69 |
70 | 8. Get a distinct set of cities and states:
71 |
72 | SELECT DISTINCT city, state FROM contributions;
73 |
74 |
75 |
76 | h3. THE WHERE CLAUSE
77 |
78 | 9. Add some conditions to the SELECT:
79 | SELECT * from contributions WHERE state='NY';
80 | Now try playing around with some of the operators:
81 |
82 | |*operator*|*description*|
83 | |=|Equal|
84 | |<>|Not equal*|
85 | |>|Greater than|
86 | |<|Less than|
87 | |>=|Greater than or equal|
88 | |<=|Less than or equal|
89 |
90 | Here are some examples:
91 | SELECT * from contributions WHERE amount > 500;
92 | SELECT * from contributions WHERE amount >= 500;
93 | SELECT last_name from contributions WHERE state <> 'NY';
94 |
95 |
96 |
97 | 10. Combine conditions with AND or OR:
98 |
99 | Find only the big spenders from New York
100 | SELECT * FROM contributions WHERE city = 'NEW YORK' AND amount > 2000;
101 |
102 | Find any big spender and anyone from New York
103 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR amount > 2000;
104 |
105 |
106 |
107 | 11. But watch out for operator precedence
108 |
109 | Looking for big spenders from Las Vegas and New York City
110 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR city = 'LAS VEGAS' AND amount > 2000;
111 |
112 | How did Mark Ruffalo sneak in there?
113 |
114 | Try that again:
115 | SELECT * FROM contributions WHERE (city = 'NEW YORK' OR city = 'LAS VEGAS') AND amount > 2000;
116 |
117 |
118 |
119 | h3. Pick One: Using BETWEEN
and IN
(NOT IN
)
120 |
121 | 11. Find all contributions between $500 and $1000
122 | SELECT * FROM contributions WHERE amount BETWEEN 251 AND 2699;
123 | (Note: this query returns the same results as SELECT * FROM contributors WHERE amount >= 500 AND amount <= 1000;
-- but it's much more readable.)
124 |
125 |
126 |
127 | 12. Find all contributors from a list of states:
128 | SELECT * from contributions WHERE state IN ('OH', 'NY');
129 |
130 | (Note: A compound statement could accomplish this same goal: state = 'OH' OR state = 'NY'
131 | But the IN
syntax makes things much clearer, and it's easier to write.)
132 |
133 |
134 |
135 | 13. Use NOT IN
to find results where a value is not included in the given set:
136 | SELECT * FROM contributions WHERE state NOT IN ('NY', 'OH');
137 |
138 |
139 |
140 |
141 |
142 | h3. Sorting the results
143 |
144 | 14. Use ORDER BY to sort:
145 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount;
146 | And reverse the order:
147 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount DESC;
148 | And order by more than one column:
149 | SELECT state, last_name, amount FROM contributions ORDER BY state, amount DESC;
150 |
151 |
152 |
153 | h3. Limiting the number of rows returned
154 |
155 | 15. Return only the top two contributions:
156 | SELECT * FROM contributions ORDER BY amount DESC LIMIT 2;
157 |
158 |
159 |
160 | h3. Changing values with UPDATE
161 |
162 | 16. Check the list of state names again:
163 | SELECT state FROM contributions;
164 |
165 | Let's correct Nebraska:
166 | UPDATE contributions SET state = 'NE' WHERE state = 'Nebraska';
167 |
168 | And check again:
169 | SELECT DISTINCT state FROM contributions;
170 |
171 |
172 |
173 |
174 | h3. DELETING rows
175 |
176 | 17. Let's get rid of a row:
177 | SELECT * FROM contributions WHERE id = 1;
178 | DELETE FROM contributions WHERE id = 1;
179 |
180 |
181 |
182 |
183 |
184 |
185 | h3. Importing data from a flat file
186 |
187 | 18. Import a delimited file:
188 | a. Go to ["https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt":https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt] (Or grab it from the conference computer.)
189 |
190 | b. Save the file as "contributions.txt" somewhere you can find it (your desktop is a good place).
191 |
192 | c. Click the SQLite Manager Import Wizard icon (!./images/import_icon.png!).
193 |
194 | * Using the **Select File** button, browse for the **contributions.txt** file you just saved.
195 | * Check the "First row contains column names" check box.
196 | * Select **Pipe(|)** for "Fields separated by"
197 | * For everything else, you can keep the default selections.
198 | * You should have 204 rows of data.
199 |
200 |
--------------------------------------------------------------------------------
/IRE2016/part2/data/candidates.txt:
--------------------------------------------------------------------------------
1 | id|committee_id|last_name|first_name|middle_name|party
2 | 1|C00580100|TRUMP|DONALD|J|REP
3 | 2|C00574624|CRUZ|RAFAEL "TED"|EDWARD|REP
4 | 3|C00458844|RUBIO|MARCO||REP
5 | 4|C00581876|KASICH|JOHN|R|REP
6 | 5|C00573519|CARSON|BENJAMIN|S|REP
7 | 6|C00577130|SANDERS|BERNARD||DEM
8 | 7|C00575795|CLINTON|HILLARY|RODHAM|DEM
9 | 8|C00578658|O'MALLEY|MARTIN|JOSEPH|DEM
10 | 9|C00579458|BUSH|JEB||REP
11 | 10|C00580399|CHRISTIE|CHRISTOPHER|J|REP
12 | 11|C00575449|PAUL|RAND||REP
13 | 12|C00577312|FIORINA|CARLY||REP
14 | 13|C00578757|GRAHAM|LINDSEY|O|REP
15 | 14|C00577981|HUCKABEE|MIKE||REP
16 |
--------------------------------------------------------------------------------
/IRE2016/part2/data/contributions.txt:
--------------------------------------------------------------------------------
1 | id|committee_id|entity_type|last_name|first_name|middle_name|city|state|zip_code|employer|occupation|date|amount|candidate_id
2 | |C00575795|IND|BUFFETT|WARREN||OMAHA|Nebraska|68131|BERKSHIRE HATHAWAY|CHAIRMAN|2015-04-15|2700|7
3 | |C00577130|IND|RUFFALO|MARK||NEW YORK|NY|100031526|SELF-EMPLOYED|ACTOR|2015-06-02|250|6
4 | |C00458844|IND|ADELSON|SHELDON||LAS VEGAS|NV|89145|||2015-06-12|2600|3
5 | |C00579458|IND|MANNING|PEYTON MR.||CLEVELAND|OH|441141717|DENVER BRONCOS|PROFESSIONAL ATHLETE|2015-08-04|2700|9
6 | |C00575795|IND|COPPOLA|SOFIA||NEW YORK|NY|100130778|SELF-EMPLOYED|DIRECTOR/WRITER/ACTOR|2016-01-22|2700|7
7 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-14|200|5
8 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-28|250|5
9 | |C00573519|IND|STANFIELD|AMY||FRANKLIN|TN|370675672|SELF-EMPLOYED|ARTIST|2015-03-31|250|5
10 | |C00573519|IND|STARK|CHERYL|ANN|ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|MARKETING RESEARCH|2015-03-11|500|5
11 | |C00573519|IND|STARK|FRED||ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|CEO|2015-03-19|1000|5
12 | |C00573519|IND|STEBBENS|KIM||EVERETT|WA|982011557|WAYA GROUP INC|EXECUTIVE|2015-03-14|250|5
13 | |C00573519|IND|STEGEMANN|BELINDA||CLINT|TX|798365308|RETIRED|RETIRED|2015-03-28|500|5
14 | |C00573519|IND|STEIGERWALD|DONALD||ESCONDIDO|CA|920263942|STEIGERWALD DOUGHERTY INC|BUILDING CONTRACTOR|2015-03-04|250|5
15 | |C00573519|IND|STEINKAMP|JEFFREY||ROCHESTER|VT|057670098|RETIRED|RETIRED|2015-03-31|1500|5
16 | |C00573519|IND|STENGEL|LINDA||SIOUX FALLS|SD|571058110|RETIRED|RETIRED|2015-03-30|250|5
17 | |C00573519|IND|STENSETHER|BARBARA|L|TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500|5
18 | |C00573519|IND|STENSETHER|JOHN||TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500|5
19 | |C00573519|IND|STEWARDSON|MELINDA||BUFFALO GAP|TX|795082140|WYLIE INDEPENDENT SCHOOL DISTRICT|READING TEACHER|2015-03-31|250|5
20 | |C00573519|IND|STOCKSTILL|JAMES||PICAYUNE|MS|394665552|RETIRED|RETIRED|2015-03-04|250|5
21 | |C00573519|IND|STODDARD|CHERYL||FREDERICKSBURG|VA|224052180|ANTHEM|REGIONAL MANAGER|2015-03-31|250|5
22 | |C00573519|IND|STOKER|RICHARD||MIAMI BEACH|FL|331417401|RETIRED|RETIRED|2015-03-24|300|5
23 | |C00573519|IND|THORNTON|JOE||DALLAS|TX|752254816|HFF|REAL ESTATE CAPITAL MARKETS|2015-03-05|2700|5
24 | |C00573519|IND|TIMBLE|JAMES||FRANKLIN GROVE|IL|610319555|RETIRED|RETIRED|2015-03-28|250|5
25 | |C00573519|IND|TOBB|RONALD||BROOKEVILLE|MD|208333208|BOWLES FLUIDICS|OPERATIONS VP|2015-03-03|250|5
26 | |C00573519|IND|TOLLAKSON|DARLENE|M|SOUTH WAYNE|WI|535879761|||2015-03-30|400|5
27 | |C00573519|IND|TOMANN|DON||BUFFALO|MN|553134253|UMC INC.|BUSINESS OWNER/PROFESSIONAL|2015-03-03|250|5
28 | |C00573519|IND|TORRENCE|DARREN||PENSACOLA|FL|325075234|SELF-EMPLOYED|OWNER|2015-03-18|250|5
29 | |C00573519|IND|TORRE|THOMAS||CUMMING|GA|300411205|AT&T|ENGINEER|2015-03-23|250|5
30 | |C00573519|IND|TRAN|VINCENT||CRESCENT CITY|CA|955319576|STATE OF CALIFORNIA|DENTIST|2015-03-04|1000|5
31 | |C00574624|IND|CHOATE|CHARLIE||BURLESON|TX|760282217|SELF EMPLOYED|SMALL BUSINESS OWNER|2015-03-31|250|2
32 | |C00574624|IND|CHOR|MARLENE||ANACONDA|MT|597112904|||2015-03-31|500|2
33 | |C00574624|IND|MACDONALD|LENNA|R|DANIEL ISLAND|SC|294927523|BVCC LLC|ENTREPRENEUR|2015-03-25|1000|2
34 | |C00574624|IND|MACH|STEVEN|P|HOUSTON|TX|772190630|MACH INDUSTRIAL GROUP LP|VP FINANCE|2015-03-23|2700|2
35 | |C00574624|IND|MACKEY|WILLIAM||MIAMI|FL|331566023|||2015-03-31|500|2
36 | |C00574624|IND|MADDOX|MATTHEW|MATT|HOUSTON|TX|770083017|BROTHERS ALVARADO; P.C.|ATTORNEY|2015-03-30|1000|2
37 | |C00574624|IND|MADSON|RYAN||EL DORADO HILLS|CA|957629665|NA|N/A|2015-03-28|1000|2
38 | |C00574624|IND|MAGGLOS|LINDA||MALIBU|CA|902653746|HOMEMAKER|HOMEMAKER|2015-03-24|1000|2
39 | |C00574624|IND|MAGNESS|SOPHIE||HOUSTON|TX|770571814|MAGNESS ORTHODONTICS|DIRECTOR OF MARKETING|2015-03-23|500|2
40 | |C00574624|IND|MALONEY|THOMAS||HAMPTON BAYS|NY|119462826|SHINNECOCK HARDWARE|OWNER|2015-03-25|1000|2
41 | |C00574624|IND|MANN|JODI||STUDIO CITY|CA|916043855|GJ SULLIVAN|BROKER|2015-03-24|1000|2
42 | |C00574624|IND|MANN|KEN||STUDIO CITY|CA|916043855|COVERX|INSURANCE|2015-03-24|1000|2
43 | |C00574624|IND|MANN|RICHARD|F|PONTE VEDRA BEACH|FL|320824609|RETIRED|RETIRED|2015-03-31|200|2
44 | |C00574624|IND|MANNING|JOHN|OWEN|AUSTIN|TX|787315848|GREAT POINT CAPITAL|TRADER|2015-03-31|5400|2
45 | |C00574624|IND|HARDY|LONNIE||SHREVEPORT|LA|711192503|SELF EMPLOYED|CPA|2015-03-23|1000|2
46 | |C00574624|IND|MARACCHINI|CHRIS||CEDAR HILL|TX|751041003|AMERICAN AIRLINES|PILOT|2015-03-24|1000|2
47 | |C00574624|IND|MARDIGIAN|DAVID||BLOOMFIELD HILLS|MI|483040934|MCM MANAGEMENT CORPORATION|CEO|2015-03-31|5400|2
48 | |C00574624|IND|HARDAWAY|MIKE||MCKINNEY|TX|750706221|RAYTHEON COMPANY|TECH WRITER/EDITOR|2015-03-24|500|2
49 | |C00574624|IND|HARIPRASAD|SATISH||EAST STROUDSBURG|PA|183027984|SELF EMPLOYED|PRINTER|2015-03-24|500|2
50 | |C00574624|IND|HARPER|JIM||BIRMINGHAM|MI|480091311|RETIRED|RETIRED|2015-03-24|1000|2
51 | |C00574624|IND|HARRELL|KEITH||MCKINNEY|TX|750717390|BUSINESS OWNER|COUNSELOR/RESTAURANT OWNER|2015-03-25|5400|2
52 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|5400|2
53 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|-2700|2
54 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|2700|2
55 | |C00458844|IND|IRIZARRY|STEVEN||WASHINGTON|DC|200041008|ROBERTI+WHITE LLC|CONSULTANT|2014-12-22|2500|3
56 | |C00458844|IND|SIMMONS|ANNETTE|C|DALLAS|TX|752402620|HOMEMAKER|HOMEMAKER|2014-12-17|5000|3
57 | |C00458844|IND|MANTENA|RAMA|R|JUPITER|FL|334774202|P4 HEALTHCARE|CEO|2014-11-19|5000|3
58 | |C00458844|IND|PATTEN|CAROLYN|A|PORT SAINT LUCIE|FL|349863252|UNIVERSITY OF FLORIDA||2015-02-17|250|3
59 | |C00458844|IND|PETHOKOUKIS|JOHN|MR|WESTERN SPRINGS|IL|605582013|MORGAN STANLEY|FINANCIAL ADVISOR|2015-02-25|1000|3
60 | |C00458844|IND|PETHOKOUKIS|SARA||WESTERN SPRINGS|IL|605582013|HOMEMAKER|HOMEMAKER|2015-02-25|1000|3
61 | |C00458844|IND|PLOMARITIS|TITUS|MR|PELHAM|NH|030765003|RETIRED|RETIRED|2015-03-31|1000|3
62 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|5000|3
63 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|-2300|3
64 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|2300|3
65 | |C00577130|IND|HOLZHAUER|FRED||NOVATO|CA|949471909|METHOD PRODUCTS, PBC|CHEMIST|2015-06-30|250|6
66 | |C00577130|IND|HONG|PENELOPE||ROCKPORT|TX|783823610|NOT EMPLOYED|RETIRED|2015-06-30|250|6
67 | |C00577130|IND|WYATT|EDNA||SANTA FE|NM|875012242|SELF-EMPLOYED|CARPENTER|2015-05-20|300|6
68 | |C00577130|IND|YOUNKIN|RANDY||YOUNGSTOWN|OH|445052563|||2015-05-20|500|6
69 | |C00577130|IND|SHEWFELT|MATTHEW||LOS ANGELES|CA|900263322|WILSHIRE ESCROW COMPANY|ESCROW OFFICER|2015-06-18|250|6
70 | |C00577130|IND|ROTHNER|GLENN||PASADENA|CA|911052720|ROTHNER, SEGALL & GREENSTONE|ATTORNEY|2015-06-18|250|6
71 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400|6
72 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400|6
73 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300|6
74 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300|6
75 | |C00577130|IND|KAST|RICHARD||BURLINGTON|VT|054082544|SELF-EMPLOYED|PHYSICIAN|2015-06-18|212|6
76 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200|6
77 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200|6
78 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250|6
79 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250|6
80 | |C00577130|IND|MCDANIEL|MICHAEL|J|SAN DIEGO|CA|921082806|SELF|MD|2015-06-18|200|6
81 | |C00577130|IND|ALLEN|BRUCE||LAUGHLIN|NV|890280673|SELF-EMPLOYED|CLINICAL PSYCHOLOGIST|2015-06-02|2700|6
82 | |C00577130|IND|ALLEN|YOKO||LAUGHLIN|NV|890280673|N/A|HOMEMAKER|2015-06-02|2700|6
83 | |C00577130|IND|ROBERTSON|JOAN|R|MILWAUKEE|WI|532174340|||2015-06-10|1000|6
84 | |C00577130|IND|MURRAY|BRIAN||LOS ANGELES|CA|900344551|SHEPPARD MULLIN LLP|ATTORNEY|2015-06-18|250|6
85 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500|6
86 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500|6
87 | |C00577130|IND|PAUL|JANE||LOS ANGELES|CA|900662840|ANTIOCH UNIVERSITY|TEACHER|2015-06-18|250|6
88 | |C00577130|IND|PRUITT|GRETA||LA CRESCENTA|CA|912141541|NOT EMPLOYED|RETIRED|2015-06-18|250|6
89 | |C00577130|IND|PULICE|MICHAEL||LOS ANGELES|CA|900683128|HOUSEBLEND MEDIA|PRODUCTION ASSISTANT|2015-06-18|250|6
90 | |C00580100|IND|ANDALORO|JIM||MARBLEHEAD|MA|01945|METAL TRONICS, INC.|OWNER|2015-06-30|500|1
91 | |C00580100|IND|ANTON|FRANCINE||SPRING LAKE|MI|49456|RETIRED|RETIRED|2015-06-24|250|1
92 | |C00580100|IND|ATKINS|LORI||SAN ANTONIO|TX|78231|TEXAS SINUS CENTER|PHYSICIAN ASSISTANT|2015-06-20|250|1
93 | |C00580100|IND|BINGHAM|RON||JACKSON|TN|38305|EMG CLINIS OF TENNESSEE|MD|2015-06-19|500|1
94 | |C00580100|IND|BLUE|JAN||HUNTINGTON BEACH|CA|92648|HOAG HEALTH|SENIOR VICE PRESIDENT|2015-06-17|500|1
95 | |C00580100|IND|BRIDGES|PAMELA||LAUREL|MS|39443|INTERNATIONAL FIRE|PRESIDENT|2015-06-26|250|1
96 | |C00580100|IND|BYRNES|JECOAH||COLORADO SPRINGS|CO|80920|EMBREE CAPITAL MARKETS GROUP, INC.|SALES|2015-06-16|250|1
97 | |C00580100|IND|CANNON|WANDA||BEVERLY HILLS|CA|90210|RETIRED|RETIRED|2015-06-16|250|1
98 | |C00580100|IND|CARRERAS|DENNIS||COCONUT CREEK|FL|33073|BERSTONE PAYMENT SYSTEMS, LLC|CEO|2015-06-17|250|1
99 | |C00580100|IND|CARTER|SCOTT||LUBBOCK|TX|79407|OTTO'S GRANARY|MANAGER/OWNER|2015-06-19|250|1
100 | |C00580100|IND|CHAMPION|STEPHAN||DESTIN|FL|32541|AC LEGG|SALES|2015-06-17|250|1
101 | |C00580100|IND|COOKINGHAM|GAIL||ROCHESTER HILLS|MI|48307|SELF-EMPLOYED|PHYSICIAN|2015-06-30|250|1
102 | |C00580100|IND|CRAICHY|KINSEY||TAMPA|FL|33601|LIVING FUEL|CEO|2015-06-29|250|1
103 | |C00580100|IND|CRUME|W|HAYDEN|COLUMBUS|MS|39705|RETIRED|RETIRED|2015-06-16|2700|1
104 | |C00580100|IND|CRUMPLER|MARK||ASHDOWN|AR|71822|DOMTAR|MECHANIC|2015-06-29|250|1
105 | |C00580100|IND|CUGINI|CHRISTY||NAPLES|FL|34119|MILLENIUM|PHYSICIAN|2015-06-25|250|1
106 | |C00580100|IND|MCGEORGE|EDWARD||RICHMOND|VA|23238|MCGEORGE ROLLING HILLS RV|CEO|2015-06-26|2700|1
107 | |C00580100|IND|MCKAY|THOMAS||AUSTIN|TX|78720|TOM'S WAY INC.|MACHINIST|2015-06-22|250|1
108 | |C00580100|IND|MCNERNEY|MICHAEL||SAN PEDRO|CA|90731|MCNERNEY'S, INC|FUNERAL SERVICE PROVIDER|2015-06-18|500|1
109 | |C00580100|IND|MCPHERSON|EDWARD||LOS ANGELES|CA|90057|SELF-EMPLOYED|PHYSICIAN|2015-06-21|250|1
110 | |C00580100|IND|MORE|MICHAEL||MARLBOROUGH|MA|01752|TJX|INFRASTRUCTURE ENGINEER III|2015-06-25|350|1
111 | |C00580100|IND|PERSSON|ALFRED||HEMET|CA|92545|CAB CHRISTIAN INC|CEO|2015-06-16|250|1
112 | |C00580100|IND|NEW|JOSEPH||CARROLLTON|GA|30116|BARNES VAN LINES|CEO|2015-06-17|250|1
113 | |C00580100|IND|NEWMAN|PAMELA||NEW YORK|NY|10017|AON RISK SERVICES|EXECUTIVE|2015-06-01|2700|1
114 | |C00580100|IND|NICKELL|JERRY||AUBREY|TX|76227|SELF-EMPLOYED|CONSULTANT|2015-06-29|250|1
115 | |C00575795|IND|LOMBARDO|MICHAEL||SHERMAN OAKS|CA|914035345|HBO|TELEVISION EXECUTIVE|2015-04-27|2700|7
116 | |C00575795|IND|STAFFORD|AMANDA||MCLEAN|VA|221021431|N/A|RETIRED|2015-04-28|2700|7
117 | |C00575795|IND|WHITAKER|DAVID||FAYETTEVILLE|AR|727011611|SELF-EMPLOYED|ATTORNEY|2015-05-07|201|7
118 | |C00575795|IND|LIM|TIM||WASHINGTON|DC|200094582|PRECISION NETWORK|PRESIDENT|2015-04-12|250|7
119 | |C00575795|IND|GEIGER|MARC||LOS ANGELES|CA|900691401|WILLIAM MORRIS ENDEAVOR|AGENT / HEAD OF MUSIC|2015-05-01|2700|7
120 | |C00575795|IND|HAMILTON|JOHN||DALLAS|TX|752143452|AS MANAGEMENT|REAL ESTATE|2015-05-07|2700|7
121 | |C00575795|IND|WALLER|KATHY||ATLANTA|GA|303271800|THE COCA-COLA COMPANY|CFO|2015-04-28|2700|7
122 | |C00575795|IND|WINGENS|GARY||LIVINGSTON|NJ|070393424|LOWENSTEIN SANDLER LLP|ATTORNEY|2015-04-17|2700|7
123 | |C00575795|IND|EDINGTON|PATRICIA||MOBILE|AL|366022006|SELF-EMPLOYED|ANTIQUES APPRAISER|2015-04-13|500|7
124 | |C00575795|IND|ALFERNESS|JOY||SAN FRANCISCO|CA|941072734|NOT EMPLOYED|HUMANITARIAN|2015-05-02|1700|7
125 | |C00575795|IND|FLYNN|JOHN||VIENNA|VA|221816131|N/A|RETIRED|2015-05-14|500|7
126 | |C00575795|IND|KASSAN|ALEX||NEW YORK|NY|10013|ANCHORAGE MEDIA GROUP|PRODUCTION|2015-04-28|2700|7
127 | |C00575795|IND|SENATORE|BRAD||BOSTON|MA|021162671|SELF-EMPLOYED|FASHION DESIGN|2015-06-30|1000|7
128 | |C00575795|IND|HELLER TRIPENY|MARY||CORNING|NY|148309481|SELF-EMPLOYED||2015-05-08|2700|7
129 | |C00575795|IND|FINKEL|JUDITH||HOUSTON|TX|770245404|N/A|RETIRED|2015-06-01|2700|7
130 | |C00575795|IND|FORD|ARLENE||BALTIMORE|MD|212101526|N/A|RETIRED|2015-06-19|300|7
131 | |C00575795|IND|NEWMAN|MELISSA||ALEXANDRIA|VA|223142414|CENTURYLINK|ATTORNEY|2015-04-20|1000|7
132 | |C00575795|IND|CANTU|ALONZO||MCALLEN|TX|785042202|CANTU CONSTRUCTION & DEVELOPMENT|OWNER/DEVELOPER|2015-06-30|2700|7
133 | |C00575795|IND|HARRIS|MAYA||NEW YORK|NY|100366812|HILLARY FOR AMERICA|SENIOR POLICY ADVISOR|2015-06-30|2700|7
134 | |C00575795|IND|OTTINGER|BARBARA||PASADENA|CA|911051342|||2015-05-13|250|7
135 | |C00575795|IND|HAIRSTON|JAMES||NEWARK|NJ|071121708|N/A|RETIRED|2015-04-30|225|7
136 | |C00575795|IND|ELLISON|CARL||NEW YORK|NY|101281248|N/A|RETIRED|2015-06-23|2700|7
137 | |C00575795|IND|MARDIROSSIAN|SHANT||KATONAH|NY|105362919|KOHLBERG & CO., LLC|PARTNER AND COO|2015-06-28|2700|7
138 | |C00575795|IND|RATNER|TAWNY||CLEVELAND HEIGHTS|OH|441063138|||2015-04-26|2700|7
139 | |C00575795|IND|LINDEN|MARTHA||ANCHORAGE|AK|995073970|OWEN R. BELL, MD, APC|CERTIFIED NURSE MIDWIFE|2015-04-13|250|7
140 | |C00581876|IND|DEMLER|JOHN||NORTHFIELD|IL|600933117|RETIRED|SALES|2015-09-29|500|4
141 | |C00581876|IND|HUMPHREY|GORDON||CHICHESTER|NH|032586102|RETIRED|RETIRED|2015-09-29|2700|4
142 | |C00581876|IND|PELLEGRINO|BOB||CINCINNATI|OH|452433220|RETIRED|INVESTOR|2015-09-29|250|4
143 | |C00581876|IND|BOND|JAMES|D|FARGO|ND|581047058|COLLINS & COMPANY|EXECUTIVE|2015-09-29|250|4
144 | |C00581876|IND|PALAFOUTAS|JUDITH||ALEXANDRIA|VA|223144761|GEORGETOWN UNIVERSITY|RESEARCH DIRECTOR|2015-09-29|1000|4
145 | |C00581876|IND|WINSLOW|CLARK||BELVEDERE TIBURON|CA|949202426|WINSLOW CAPITAL|INVESTMENT MGMT|2015-09-29|1000|4
146 | |C00581876|IND|YOUNG|STEWART||WASHINGTON|DC|200024489|CORLEY CONSULTING|LOBBYIST|2015-09-29|250|4
147 | |C00581876|IND|BATTOCLETTI|DAVID||COLUMBUS|OH|432157513|ICE MILLER WHITEBOARD|LOBBYIST|2015-09-29|1000|4
148 | |C00581876|IND|COLEMAN|GEORGE||FAIRFIELD|CT|068245649|CREDIT SUISSE|BANKER|2015-09-29|500|4
149 | |C00581876|IND|SWALDO|THEODORE||NORTH CANTON|OH|447208807|RETIRED|RETIRED|2015-09-29|250|4
150 | |C00581876|IND|OSTERTHALER|ROBERT||VIENNA|VA|221821368|RETIRED|CEO|2015-09-29|900|4
151 | |C00581876|IND|BERGAN|PHILIP||CHARLESTON|SC|294012403|RETIRED|RETIRED|2015-09-29|500|4
152 | |C00581876|IND|DUBRAVCIC|STEPHEN||BRONWOOD|GA|398260083|DARKOTECH, INC|MANAGER|2015-08-07|250|4
153 | |C00581876|IND|BRISTOW|JULIE||CINCINNATI|OH|452083332|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700|4
154 | |C00581876|IND|WASSERSTROM|ALAN||COLUMBUS|OH|432072167|WASSERSTROM COMPANIES|CEO|2015-08-07|2700|4
155 | |C00581876|IND|SANDRIDGE|RHONDA|L|WESTFIELD CENTER|OH|442519801|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700|4
156 | |C00581876|IND|WILSON|RONALD||SOLON|OH|441395077|GENERAL ELECTRIC|GENERAL MANAGER|2015-08-07|500|4
157 | |C00581876|IND|BRISTOW|WILLIAM|S|CINCINNATI|OH|452083332|JEFF WYLER AUTOMATIVE FAMILY|PRESIDENT|2015-08-07|2700|4
158 | |C00581876|IND|FETTER|STEVEN||PORT TOWNSEND|WA|983683058|SELF-EMPLOYED|UTILITY CONSULTANT|2015-08-07|2700|4
159 | |C00581876|IND|BECHTOLD|TIMOTHY||COLUMBUS|OH|432156108|VORYS SATER|LOBBYIST|2015-08-07|500|4
160 | |C00581876|IND|STEWART|JENNIFER||NEW HOPE|PA|189389246|STUDENT|STUDENT|2015-08-07|250|4
161 | |C00581876|IND|ELSANT|MARTIN||WOODMERE|NY|115982909|NORTH SHORE HEALTH SYSTEM|RADIOLOGIST|2015-08-07|200|4
162 | |C00581876|IND|THOMPSON|LUCINA||DALLAS|TX|752303038|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|2700|4
163 | |C00581876|IND|EARL|SUSAN||COLUMBUS|OH|432061275|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|250|4
164 | |C00581876|IND|MAUER|VINCENT||CINCINNATI|OH|452443604|BROCK BROWN COD|LAWYER|2015-08-18|250|4
165 | |C00580399|IND|COHEN|LARRY||NY|NY|100143744|SEVEN BRIDGES ADVISORS|FINANCIAL ADVISOR|2015-08-13|2700|10
166 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-09-03|859|10
167 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-08-15|1840|10
168 | |C00580399|IND|GUREGHIAN|VAHAN|H|GLADWYNE|PA|190351507|CSMI LLC|FOUNDER AND CEO|2015-09-30|2700|10
169 | |C00580399|IND|PJETERNIKAJ|LILA||SADDLE RIVER|NJ|074583012|||2015-08-04|1350|10
170 | |C00580399|IND|CONSIDINE|THOMAS||SPRING LAKE|NJ|077622369|GRAVILAUR SOLUTIONS LLC|CONSULTANT|2015-09-29|2700|10
171 | |C00580399|IND|CONSORTI|JASON||MONROE|NJ|088312242|CSC|IT MANAGER|2015-07-01|500|10
172 | |C00580399|IND|CONSTABLE|RICHARD||SOUTH ORANGE|NJ|070791141|US ATTORNEY|LAWYER/LEGAL|2015-09-09|1000|10
173 | |C00580399|IND|CONTI|GINA||NEW PROVIDENCE|NJ|079742117|HOMEMAKER|HOMEMAKER|2015-09-30|2500|10
174 | |C00580399|IND|CONTI|KURT|G|NEW PROVIDENCE|NJ|079742117|CONTI GROUP|PRESIDENT/CEO|2015-09-30|2500|10
175 | |C00580399|IND|CONWAY|ARTHUR|W|MAHWAH|NJ|074302040|DIALAMERICA MARKETING INC.|PRESIDENT & CEO|2015-07-16|2700|10
176 | |C00580399|IND|GIBBONS|MARY|M|BASKING RIDGE|NJ|079204107|ELBERON DEVELOPMENT GROUP ST. CLAIRE'|ADMINISTRATOR/SOCIAL WORKER|2015-08-20|1000|10
177 | |C00580399|IND|GIBLIN|BRENDON|P|SOUTHBOROUGH|MA|017721706|BRENDON PROPERTIES|DEVELOPER REAL ESTATE|2015-09-08|500|10
178 | |C00580399|IND|GIDWITZ|CHRISTINA||CHICAGO|IL|606065829|HOUSEWIFE|HOUSEWIFE|2015-09-27|2700|10
179 | |C00580399|IND|GILFILLAN|CHRISTINE|C|MORRISTOWN|NJ|079607355|THE MCJ AMELIOR FOUNDATION|PRESIDENT|2015-07-02|2700|10
180 | |C00580399|IND|GILFILLAN|MICHAEL|T|MADISON|NJ|079402751|BRICK CITY SPORTS CAPITAL LLC|INVESTMENTS|2015-07-02|2700|10
181 | |C00580399|IND|GILMAN|J|PAUL|MENDHAM|NJ|079451205|COVANTA ENERGY|SENIOR VICE PRESIDENT AND CHIEF SUSTAI|2015-07-31|2700|10
182 | |C00580399|IND|GILMAN|THOMAS||SCOTTSDALE|AZ|852623818|DAIMLERCHRYSLER FINANCIAL SERVICES AME|CEO|2015-07-27|2700|10
183 | |C00580399|IND|GILMORE|THOMAS|P|ANDOVER|NJ|078214127|GILMORE ELECTRIC INC.|ELECTRICIAN|2015-07-24|2700|10
184 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700|10
185 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700|10
186 | |C00580399|IND|CONSIGLIO|THOMAS||RAMSEY|NJ|074461346|RESOURCE REALTY|SALES|2015-08-03|2700|10
187 | |C00580399|IND|COLE|BRIAN||OAKLAND|NJ|074362350|COLE MEDICAL INC|VICE PRESIDENT|2015-07-01|2700|10
188 | |C00579458|IND|VILLARI|DAVID|J|FORT LAUDERDALE|FL|333061906|GIG INS GROUP|BUSINESS OWNER|2015-11-30|250|9
189 | |C00579458|IND|VIEIRA|SEAN||FAIRFAX|VA|220336226|SJV LLC|PRESIDENT|2015-11-29|1000|9
190 | |C00579458|IND|VIJAYANAGAR|RAGHAVENDRA||TAMPA|FL|336063573|R VIJAYANAGAR M.D. P.A.|SURGEON|2015-11-20|2000|9
191 | |C00579458|IND|VILLARREAL|AARON||MCALLEN|TX|785044405|||2015-10-30|2700|9
192 | |C00579458|IND|VILLAMIZAR|JOHN||ROYAL PALM BEACH|FL|334116107|ADVANCED VISION|OPTICIAN|2015-12-29|375|9
193 | |C00579458|IND|WARE|BLAKE|BEAKLEY|AMARILLO|TX|791092331|HOMEMAKER|HOMEMAKER|2015-11-19|2000|9
194 | |C00579458|IND|WARD|JIM||PHOENIX|AZ|850162363|THE PHOENIX SYMPHONY|CEO|2015-10-14|1000|9
195 | |C00579458|IND|WARD|JOHN|M|DALLAS|TX|752047849|RETIRED|RETIRED|2015-11-09|1000|9
196 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|4000|9
197 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|-2000|9
198 | |C00579458|IND|WAREHAM|KRISTINA||LAKE HIAWATHA|NJ|070342209|PRECISION CASTPARTS CORP|ENGINEER|2015-12-31|1000|9
199 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|-2700|9
200 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|2700|9
201 | |C00579458|IND|MANNING|RALPH|F|MARS|PA|160462633|TUCKER ARENSBERG PC|ATTORNEY|2015-11-10|1000|9
202 | |C00579458|IND|MANNING|RAMON||HOUSTON|TX|770211611|PARTNERS ENERGY|INVESTOR|2015-10-28|250|9
203 | |C00579458|IND|MANNING|SAM|BLAGDEN|DALLAS|TX|752195220|SELF-EMPLOYED|INVESTMENTS|2015-11-10|500|9
204 | |C00579458|IND|MANRIQUE|FRANCISCO||DORAL|FL|331783505|||2015-10-20|500|9
205 |
--------------------------------------------------------------------------------
/IRE2016/part2/images/ff-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part2/images/ff-menu.png
--------------------------------------------------------------------------------
/IRE2016/part2/images/import_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part2/images/import_icon.png
--------------------------------------------------------------------------------
/IRE2016/part2/images/new_database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/IRE2016/part2/images/new_database.png
--------------------------------------------------------------------------------
/IRE2016/part2/part2.textile:
--------------------------------------------------------------------------------
1 | h2. SQLite II: Aggregate Functions
2 |
3 | 1. Open Firefox and click on the menu icon:
4 |
5 | !./images/ff-menu.png!
6 |
7 | Use the "customize" option to find the SQLite Manager Plugin:
8 |
9 | !./images/customize-menu.png!
10 |
11 |
12 |
13 | 2. Create a new database called contributions_candidates
14 |
15 | !./images/new_database.png!
16 |
17 |
18 |
19 | 3. Use a CREATE TABLE statement to create a new contributions table:
20 |
21 |
22 |
23 |
24 | CREATE TABLE "contributions" (
25 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
26 | "committee_id" VARCHAR,
27 | "entity_type" VARCHAR,
28 | "last_name" VARCHAR,
29 | "first_name" VARCHAR,
30 | "middle_name" VARCHAR,
31 | "city" VARCHAR,
32 | "state" VARCHAR,
33 | "zip_code" VARCHAR,
34 | "employer" VARCHAR,
35 | "occupation" VARCHAR,
36 | "date" DATETIME,
37 | "amount" INTEGER,
38 | "candidate_id" INTEGER NOT NULL,
39 | FOREIGN KEY(candidate_id) REFERENCES candidates(id)
40 | );
41 |
42 |
43 |
44 | 4. Use the SQLite Manager Import Wizard (!./images/import_icon.png!) to import contributions.txt:
45 |
46 |
47 |
48 | h3. Aggregate Functions (count, max, min, sum, avg)
49 |
50 | 5. Count the number of contributors from California:
51 | SELECT COUNT(id) FROM contributions WHERE state = 'CA';
52 |
53 | 6. Select the minimum and maximum contributions:
54 | SELECT MAX(amount) FROM contributions;
55 | SELECT MIN(amount) FROM contributions;
56 |
57 | 7. Add up the contributions from Georgia:
58 | SELECT SUM(amount) FROM contributions WHERE state = 'GA';
59 |
60 | 8. Find the average contribution:
61 | SELECT AVG(amount) FROM contributions;
62 |
63 | Use GROUP BY to create subtotals
64 |
65 | 9. Find the total amount of contributions per state:
66 | SELECT state, SUM(amount) FROM contributions GROUP BY state;
67 |
68 | 10. Find the total amount of contributions per city and state:
69 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state;
70 | Now order cities by their total contributions:
71 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state ORDER BY SUM(amount) DESC;
72 |
73 | h2. Subqueries and Joins
74 |
75 | 11. Use a CREATE TABLE statement to create a new table for candidate data:
76 |
77 |
78 | CREATE TABLE "candidates" (
79 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
80 | "committee_id" VARCHAR,
81 | "first_name" VARCHAR,
82 | "last_name" VARCHAR,
83 | "middle_name" VARCHAR,
84 | "party" VARCHAR
85 | );
86 |
87 |
88 |
89 |
90 |
91 | 12. Use the SQLite Manager Import Wizard (!./images/import_icon.png!) to import candidates.txt
92 |
93 | Remember to select the pipe delimiter ("|") and to check the box indicating that the first row contains headers.
94 |
95 |
96 |
97 | h3. Using Subqueries
98 |
99 | 13. Find out the maxiumum contribution amount in the data set and see which contributors have given this amount.
100 |
101 | First, determine the maximum amount contriubuted:
102 | SELECT MAX(amount) FROM contributions;
103 |
104 | Then SELECT all fields for any contribution at that amount . . . but how?
105 |
106 | Like this?
107 | SELECT * FROM contributions WHERE amount = MAX(amount);
108 |
109 | Nope.
110 |
111 | Hardcode the amount?
112 | SELECT * FROM contributions WHERE amount = 5400;
113 |
114 | But what if next month the max changes? How can we make this dynamic?
115 |
116 | Subqueries to the rescue:
117 | SELECT * FROM contributions WHERE amount = (SELECT MAX(amount) FROM contributions);
118 |
119 |
120 |
121 |
122 | 14. Write a query that gets the sum amount of the top 20 contributions
123 |
124 | SELECT SUM(amount) FROM contributions WHERE id IN (SELECT id FROM contributions ORDER BY amount DESC LIMIT 20);
125 |
126 |
127 |
128 |
129 | h3. Using a subquery on another table
130 |
131 | 15. Find all of the contributions to Hillary Clinton
132 |
133 | SELECT * FROM contributions WHERE candidate_id = (SELECT id from candidates WHERE last_name = 'CLINTON' AND first_name = 'HILLARY');
134 |
135 |
136 |
137 |
138 | h3. Joins: Queries across tables
139 |
140 | 16. It is possible to do an *implicit* join simply by defining the relationship between the two tables in the WHERE
clause:
141 |
142 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions, candidates WHERE contributions.candidate_id = candidates.id;
143 |
144 |
145 |
146 | 17. Use table name aliases to save typing:
147 |
148 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a, candidates b WHERE a.candidate_id = b.id;
149 |
150 | This query returns the same results as the one above, but it saves some typing by making "a" an alias for "contributions" and "b" an alias for "candidates." The alias can use any valid table name you
151 | like, but obviously shorter aliases will save more typing, while longer ones may make the intention of the query easier to understand.
152 |
153 |
154 |
155 | h4. Explicit JOIN
syntax
156 |
157 | 18. Rewrite the above query using explicit JOIN syntax:
158 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions JOIN candidates ON contributions.candidate_id = candidates.id;
159 |
160 |
161 |
162 | 19. Use aliases work with JOIN
syntax:
163 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id;
164 |
165 |
166 |
167 | 20. Get the number of contributions for each candidate
168 | SELECT count(a.id), b.id, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
169 |
170 | Our list of candidates seems to be coming up short. Let's check it:
171 |
172 | SELECT DISTINCT id, last_name FROM candidates;
173 |
174 | Definitely missing candidates. What happened?
175 |
176 | Performing the JOIN
returns the same results as the query with this clause: WHERE contributions.candidate_id = candidates.id
.
177 |
178 | What if a candidate has no contributions? Then that candidate is not returned by the query.
179 |
180 | The JOIN
acts just like the WHERE
clause and filters out any rows that don't match the condition defined.
181 |
182 | Joins that return only rows in which there is a match in both tables are known as *INNER JOINs*. This is often exactly the behavior you want from the join (ignore any rows from either table that don't relate to a row in the other table). So by default, the JOIN
keyword executes an INNER JOIN
. You can also explicitly request an INNER JOIN
, just to make things clearer:
183 |
184 | SELECT count(a.id), b.id, b.last_name FROM contributions a INNER JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
185 |
186 | The results will be the same.
187 |
188 |
189 |
190 | h3. OUTER JOINS
191 |
192 | * A LEFT OUTER JOIN
includes all rows from the table on the left side of the statement and only matching rows from the table on the right side of the statement.
193 | * A RIGHT OUTER JOIN
includes all rows from the table on the right side of the statement and only matching rows from the left side of the statement.
194 | * A FULL OUTER JOIN
includes all rows from both tables.
195 |
196 | Currently, SQLite only supports LEFT OUTER JOIN
from the list above, but some other database management systems support the other two types as well.
197 |
198 | 15. Get the number of contributions for each candidate, including those with no contributions:
199 |
200 | SELECT candidates.last_name, count(contributions.id)
201 | FROM candidates LEFT OUTER JOIN contributions
202 | ON candidates.id = contributions.candidate_id
203 | GROUP BY candidates.id, candidates.last_name
204 | ORDER BY count(contributions.id);
205 |
206 |
207 | (Note: Aliases would work here as well.)
208 |
209 |
--------------------------------------------------------------------------------
/NICAR2015/candidates.txt:
--------------------------------------------------------------------------------
1 | candidate_id|candidate_name|candidate_party|election_year|office_state|candidate_office|candidate_office_district|candidate_ici|candidate_status|candidate_principle_campaign_committee|candidate_street1|candidate_street2|candidate_city|candidate_state|candidate_zip
2 | P00003608|CAIN, HERMAN|REP|2012|US|P|00|C|P|C00496067|PO BOX 2158||STOCKBRIDGE|GA|30281
3 | P20002721|SANTORUM, RICHARD J.|REP|2012|US|P|00|C|C|C00496034|P.O. BOX 37||VERONA|PA|15147
4 | P20003281|PERRY, JAMES R (RICK)|REP|2012|US|P|00|C|P|C00500587|OFFICE OF THE GOVERNOR-ST INS BLDG|1100 SAN JACINTO|AUSTIN|TX|78701
5 | P80000748|PAUL, RON|REP|2012|US|P|00|C|C|C00495820|220 BLACKSTOCK LANE||LAKE JACKSON|TX|77566
6 | P80003338|OBAMA, BARACK|DEM|2012|US|P|00|I|C|C00431445|PO BOX 8102||CHICAGO|IL|60680
7 | P80003353|ROMNEY, MITT / RYAN, PAUL D. |REP|2012|US|P|00|C|C|C00431171|585 COMMERCIAL ST.||BOSTON|MA|02109
8 |
--------------------------------------------------------------------------------
/NICAR2015/committees.txt:
--------------------------------------------------------------------------------
1 | commmittee_id|committee_name|treasurer_name|committee_state1|committee_state2|committee_city|committee_state|committee_zip|committee_dsgn|committee_type|committee_party_affiliation|committee_filing_freq|org_type|connected_org_nm|candidate_id
2 | C00431171|ROMNEY FOR PRESIDENT INC.|CRATE, DARRELL|585 COMMERCIAL ST.||BOSTON|MA|02109|P|P|REP|M||ROMNEY VICTORY INC.|P80003353
3 | C00431445|OBAMA FOR AMERICA|NESBITT, MARTIN H|PO BOX 8102||CHICAGO|IL|60680|P|P|DEM|M||OBAMA VICTORY FUND 2012|P80003338
4 | C00495820|RON PAUL 2012 PRESIDENTIAL CAMPAIGN COMMITTEE INC.|PYEATT, LORI|845 W PLANTATION DR||CLUTE|TX|77531|P|P|REP|M|||P80000748
5 | C00496034|RICK SANTORUM FOR PRESIDENT INC.|MAENZA, NADINE|PO BOX 37||VERONA|PA|15147|P|P|REP|Q|||P20002721
6 | C00496067|FRIENDS OF HERMAN CAIN INC|MARK J BLOCK|PO BOX 2158||STOCKBRIDGE|GA|30281|P|P|REP|Q|||P00003608
7 | C00500587|RICKPERRY.ORG INC|PURPURA, SALVATORE MR.|228 S WASHINGTON STREET|STE 115|ALEXANDRIA|VA|22314|P|P|REP|Q|||P20003281
8 |
--------------------------------------------------------------------------------
/NICAR2015/images/create_contributions_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2015/images/create_contributions_table.png
--------------------------------------------------------------------------------
/NICAR2015/part1_steps.textile:
--------------------------------------------------------------------------------
1 | h2. A Quick Introduction to SQL Using SQLite (Just the Steps)
2 |
3 | 1. Open Firefox and find the SQLite Manager Plugin in the tools menu:
4 |
5 | !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/sqlite_manager_ff.png!
6 |
7 | 2. Create a new database called "campaign_finance":
8 | !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/new_database.png!
9 |
10 | 3. Create a new table called "contributions" (!https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/new_table.png!) and give it the following field definitions:
11 | !https://github.com/tthibo/SQL-Tutorial/raw/master/NICAR2015/images/create_contributions_table.png!
12 |
13 | 4. Insert a row of data:
14 | Use the "Execute SQL" tab (it's in the second menu row, under the icons): !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/execute_sql.png!
15 |
16 |
17 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00494740','IND','BUFFETT','WARREN','OMAHA','Nebraska','68131','BERKSHIRE HATHAWAY/CHAIRMAN','CHAIRMAN','2500');
18 |
19 |
20 | 5. Insert three more rows (one at a time or all at once)
21 |
22 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00494740','IND','WINFREY','OPRAH','CHICAGO','IL','60607','HARPO INC.','CHAIRMAN/CEO',500);
23 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00494740','IND','PRITZKER','PENNY S','CHICAGO','IL','60614','HYATT','EXEC',2500);
24 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00431171','IND','ADELSON','SHELDON','LAS VEGAS','NV','89109','VENETIAN HOTEL','OWNER','2500');
25 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00431171','IND','MARRIOTT','BILL MR. JR.','BETHESDA','MD','20817','MARRIOTT INTERNATINAL INC.','CHAIRMAN & C.E.O.','587');
26 |
27 |
28 |
29 | 6. Select everything from the contributions table:
30 | SELECT * FROM contributions;
31 |
32 | 7. Choose some fields to select:
33 | SELECT city, state FROM contributions;
34 |
35 | 8. Get a distinct set of cities and states:
36 | SELECT DISTINCT city, state FROM contributions;
37 |
38 | h3. THE WHERE CLAUSE
39 |
40 | 9. Add some conditions to the SELECT:
41 | SELECT * from contributions WHERE state='IL';
42 | Now try playing around with some of the operators:
43 |
44 | |*operator*|*description*|
45 | |=|Equal|
46 | |<>|Not equal*|
47 | |>|Greater than|
48 | |<|Less than|
49 | |>=|Greater than or equal|
50 | |<=|Less than or equal|
51 |
52 | Here are some examples:
53 | SELECT * from contributions WHERE amount > 500;
54 | SELECT * from contributions WHERE amount >= 500;
55 | SELECT last_name from contributions WHERE state <> 'IL';
56 |
57 | 10. Combine conditions with AND or OR:
58 |
59 | Find only the big spenders from Illinois
60 | SELECT * FROM contributions WHERE state = 'IL' AND amount > 2000;
61 |
62 | Find any big spender and anyone from Illinois
63 | SELECT * FROM contributions WHERE state = 'IL' OR amount > 2000;
64 |
65 | 11. But watch out for operator precedence
66 |
67 | Looking for big spenders from Nevada and Chicago
68 | SELECT * FROM contributions WHERE city = 'CHICAGO' OR state = 'NV' AND amount > 2000;
69 |
70 | How did Oprah sneak in there?
71 |
72 | Try that again:
73 | SELECT * FROM contributions WHERE (city = 'CHICAGO' OR state = 'NV') AND amount > 2000;
74 |
75 | h3. Sorting the results
76 |
77 | 12. Use ORDER BY to sort:
78 | SELECT last_name, amount FROM contributions WHERE amount > 200 ORDER BY amount;
79 | And reverse the order:
80 | SELECT last_name, amount FROM contributions WHERE amount > 200 ORDER BY amount DESC;
81 | And order by more than one column:
82 | SELECT last_name, state, amount FROM contributions ORDER BY state, amount DESC;
83 |
84 | h3. Limiting the number of rows returned
85 |
86 | 13. Return only the top two contributions:
87 | SELECT * FROM CONTRIBUTIONS ORDER BY amount DESC LIMIT 2;
88 |
89 |
90 | h3. Changing values with UPDATE
91 |
92 | 14. Check the list of state names again:
93 | SELECT state FROM contributions;
94 |
95 | Let's correct Nebraska:
96 | UPDATE contributions SET state = 'NE' WHERE state = 'Nebraska';
97 |
98 | And check again:
99 | SELECT DISTINCT state FROM contributions;
100 |
101 | h3. DELETING rows
102 |
103 | 15. Let's get rid of a row:
104 | SELECT * FROM contributions WHERE id = 1;
105 | DELETE FROM contributions WHERE id = 1;
106 |
107 | h3. Importing data from a flat file
108 |
109 | 14. Import a delimited file:
110 | a. Go to ["https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2015/contributions.txt":https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2015/contributions.txt]
111 | b. Save the file as "contributions.txt" somewhere you can find it (your desktop is a good place).
112 |
113 | c. Click the SQLite Manager Import Wizard icon (!https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/import_icon.png!).
114 |
115 | * Using the **Select File** button, browse for the **contributions.txt** file you just saved.
116 | * Check the "First row contains column names" check box.
117 | * Select **Pipe(|)** for "Fields separated by"
118 | * For everything else, you can keep the default selections.
119 | * You should have 1006 rows of data.
120 |
121 |
122 | 
A Gentle Introduction to SQL Using SQLite by Troy Thibodeaux is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
--------------------------------------------------------------------------------
/NICAR2015/part2_steps.textile:
--------------------------------------------------------------------------------
1 | h2. An Introduction to Grouping and Summing Using SQLite (Just the Steps)
2 |
3 | h3. Review: CREATE, INSERT, SELECT and WHERE
4 |
5 | 1. Create a new database called campaign_finance (SQLite manager will save the file as campaign_finance.sqlite).
6 |
7 | 2. Create a new table called "contributions":
8 | CREATE TABLE "contributions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "committee_id" VARCHAR,
9 | "entity_type" VARCHAR, "last_name" VARCHAR, "first_name" VARCHAR, "city" VARCHAR, "state" VARCHAR, "zip_code" VARCHAR,
10 | "employer" VARCHAR, "occupation" VARCHAR, "amount" INTEGER)
11 |
12 | 3. Add a few rows of data:
13 |
14 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00494740','IND','WINFREY','OPRAH','CHICAGO','IL','60607','HARPO INC.','CHAIRMAN/CEO',500);
15 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00494740','IND','PRITZKER','PENNY S','CHICAGO','IL','60614','HYATT','EXEC',2500);
16 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00431171','IND','ADELSON','SHELDON','LAS VEGAS','NV','89109','VENETIAN HOTEL','OWNER','2500');
17 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, city, state, zip_code, employer, occupation, amount) VALUES ('C00431171','IND','MARRIOTT','BILL MR. JR.','BETHESDA','MD','20817','MARRIOTT INTERNATINAL INC.','CHAIRMAN & C.E.O.','587');
18 |
19 |
20 | 4. Import a data file (contributions.txt)
21 |
22 | 5. Write a query to select all fields from contributions of at least $500 and no more than $1000.
23 |
24 | h3. Using BETWEEN to find values in a range
25 |
26 | 6. SELECT * FROM contributions WHERE amount BETWEEN 500 AND 1000;
27 |
28 | h3. Using IN to choose from a list
29 |
30 | 7. Select all contributions from Alabama, Georgia or Florida:
31 | SELECT * FROM contributions WHERE state IN ('AL', 'GA', 'FL');
32 |
33 | 8. Select all contributions from some state other than California, Oregon or Arizona:
34 | SELECT * FROM contributions WHERE state NOT IN ('CA', 'OR', 'AZ');
35 |
36 | h3. Wildcard matching with LIKE
37 |
38 | 9. Scroll through the New York ZIP codes to see the issue:
39 | SELECT DISTINCT city, state, zip_code FROM contributions WHERE city = 'NEW YORK' AND state = 'NY' ORDER BY zip_code;
40 | SELECT zip_code FROM contributions WHERE zip_code = '10017';
41 |
42 | Use % to match any number of characters.
43 | SELECT zip_code FROM contributions WHERE zip_code LIKE '10017%';
44 |
45 | 10. Find all contributions where the middle initial is included in the first_name field:
46 | Use _ to match exactly one character.
47 | SELECT * FROM contributions WHERE first_name LIKE '% _.%';
48 |
49 | h3. Dealing with NULL values
50 |
51 | Another data problem:
52 | SELECT first_name, last_name FROM contributions WHERE state = 'NH';
53 |
54 | 11. How do we find any rows missing the last_name value?
55 | NOTE: "=" won't work.
56 | SELECT * FROM contributions WHERE last_name IS NULL;
57 |
58 | 12. How do we find any New Hampshire contribution by someone whose last name isn't "BAKER":
59 |
60 | SELECT * FROM contributions WHERE state = 'NH';
61 |
62 | SELECT * FROM contributions WHERE state = 'NH' AND last_name <> 'BAKER';
63 |
64 | SELECT * FROM contributions WHERE state = 'NH' AND (last_name <> 'BAKER' OR last_name IS NULL);
65 |
66 | 13. Grab only rows from NH where there is a value for last_name:
67 | SELECT * FROM contributions WHERE state = 'NH' AND last_name IS NOT NULL;
68 |
69 | h3. Manipulating text with string functions
70 |
71 | 14. Use TRIM() to get rid of leading and trailing whitespace
72 | a. Change Oprah's row to introduce whitepace around the state name:
73 | UPDATE contributions SET state = ' IL ' WHERE last_name = 'WINFREY';
74 | b. Now check to see that you've created a new state:
75 | SELECT DISTINCT state FROM contributions ORDER BY state;
76 | c. Use TRIM() to set things right:
77 | UPDATE contributions SET state = TRIM(state);
78 |
79 | 15. Use UPPER() or LOWER() to handle inconsistent capitalization
80 | SELECT city, state FROM contributions WHERE state = 'AL' ORDER BY city, state;
81 | SELECT * FROM contributions WHERE state = 'AL' AND city = 'BIRMINGHAM';
82 | SELECT * from contributions WHERE state = 'AL' AND UPPER(city) = 'BIRMINGHAM';
83 | NOTE: case sensitivity is system-dependent. In SQLite, LIKE is not case sensitive. In MySQL, "=" is not case sensitive.
84 | It's safer to be explicit about case so your SQL is portable.
85 |
86 | 16. Use SUBSTR() to get a substring
87 | Let's revisit the ZIP+4 problem:
88 | SELECT DISTINCT city, state, zip_code FROM contributions WHERE city = 'NEW YORK' AND state = 'NY' ORDER BY zip_code;
89 |
90 | Now let's return just the 5-digit ZIPs:
91 | SELECT SUBSTR(zip_code, 1, 5) FROM contributions;
92 |
93 |
94 | h3. Aggregate Functions
95 |
96 | 17. Count the number of contributions from California:
97 | SELECT COUNT(id) FROM contributions WHERE state = 'CA';
98 |
99 | 18. Find out how many zip codes there are in the table:
100 | SELECT COUNT(DISTINCT zip_code) FROM contributions;
101 | SELECT COUNT(DISTINCT state) FROM contributions;
102 |
103 | 19. Select the minimum and maximum contributions:
104 | SELECT MAX(amount) FROM contributions;
105 | SELECT MIN(amount) FROM contributions;
106 |
107 | 20. Find the average contribution:
108 | SELECT AVG(amount) FROM contributions;
109 |
110 | 21. Add up the contributions from Georgia:
111 | SELECT SUM(amount) FROM contributions WHERE state = 'GA';
112 |
113 |
114 | h3. Grouping with GROUP BY
115 |
116 | 22. Find the total amount of contributions per state:
117 | SELECT state, SUM(amount) FROM contributions GROUP BY state;
118 |
119 | 23. Find the total amount of contributions per city and state:
120 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state;
121 | Now order cities by their total contributions:
122 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state ORDER BY SUM(amount) DESC;
123 |
124 |
125 | h3. Using Subqueries
126 |
127 | 24. A failed attempt to get all contributions who gave the maximum:
128 | SELECT * FROM contributions WHERE amount = MAX(amount);
129 |
130 | 25. Doing it right with a subquery
131 |
132 | What we want is:
133 | SELECT MAX(amount) FROM contributions;
-- The result is 5000
134 | And then, using the result of that query:
135 | SELECT * FROM contributions WHERE amount = 5000;
136 |
137 | Combine them with a subquery:
138 | SELECT * FROM contributions WHERE amount = (SELECT MAX(amount) FROM contributions);
139 |
140 | 26. Use a subquery to total the amounts from the top 20 contributions
141 | SELECT SUM(amount) FROM contributions WHERE id IN (SELECT id FROM contributions ORDER BY amount DESC LIMIT 20);
142 |
143 |
144 | h3. Grouping with Group By
145 |
146 | 27. Get total amount contributed by state:
147 | SELECT state, SUM(amount) FROM contributions GROUP BY state;
148 |
149 | 28. Or by city (grouping by two columns):
150 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state;
151 |
152 | 29. And easily see which cities gave the most (using ORDER BY):
153 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state ORDER BY SUM(amount) DESC;
154 |
155 | 30. Be wary of any non-aggregate fields in the SELECT clause that aren't in the GROUP BY:
156 | SELECT city, state, SUM(amount) FROM contributions GROUP BY state ORDER BY SUM(amount) DESC;
157 |
158 | h3. Filtering by aggregate values using HAVING
159 |
160 | 31. A failed attempt to return totals for cities where at least $3,000 has been contributed:
161 | SELECT city, state, SUM(amount) FROM contributions WHERE SUM(amount) >= 3000 GROUP BY city, state ORDER BY SUM(amount) DESC;
162 |
163 | 32. And the way that works:
164 | SELECT city, state, SUM(amount) FROM contributions GROUP BY city, state HAVING SUM(amount) >= 10000 ORDER BY SUM(amount) DESC;
165 |
166 | 33. What's the difference betwen WHERE and HAVING?
167 | a. A simple WHERE:
168 | SELECT city, state, amount FROM contributions WHERE amount >= 2300;
169 | b. Where with a GROUP BY:
170 | SELECT city, state, SUM(amount) FROM contributions WHERE amount >= 2300 GROUP BY city, state;
171 | c. Now limiting those cities by the total contributions:
172 | SELECT city, state, SUM(amount) FROM contributions WHERE amount >= 2300 GROUP BY city, state HAVING SUM(amount) > 10000;
173 |
174 |
175 | h3. Is this data normal?
176 |
177 | * If I wanted to find all contributions to a given candidate, what query would I use?
178 | * If I wanted to get the candidate's name or the committee treasurer's name, what would I need to do? Why?
179 |
180 |
181 | 
A Gentle Introduction to SQL Using SQLite by Troy Thibodeaux is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
182 |
183 |
--------------------------------------------------------------------------------
/NICAR2016/part1/data/.#famous_donors.txt:
--------------------------------------------------------------------------------
1 | tthibodeaux@CTCIDGMBTEMP.local.24816
--------------------------------------------------------------------------------
/NICAR2016/part1/data/contributions.txt:
--------------------------------------------------------------------------------
1 | id|committee_id|entity_type|last_name|first_name|middle_name|city|state|zip_code|employer|occupation|date|amount
2 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-14|200
3 | |C00573519|IND|ST. CLAIR|ANNE|K|MECHANICSVILLE|VA|231112600|RETIRED|RETIRED|2015-03-28|250
4 | |C00573519|IND|STANFIELD|AMY||FRANKLIN|TN|370675672|SELF-EMPLOYED|ARTIST|2015-03-31|250
5 | |C00573519|IND|STARK|CHERYL|ANN|ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|MARKETING RESEARCH|2015-03-11|500
6 | |C00573519|IND|STARK|FRED||ENGLEWOOD|FL|342245434|PATHWAY LIGHTING PRODUCTS INC.|CEO|2015-03-19|1000
7 | |C00573519|IND|STEBBENS|KIM||EVERETT|WA|982011557|WAYA GROUP INC|EXECUTIVE|2015-03-14|250
8 | |C00573519|IND|STEGEMANN|BELINDA||CLINT|TX|798365308|RETIRED|RETIRED|2015-03-28|500
9 | |C00573519|IND|STEIGERWALD|DONALD||ESCONDIDO|CA|920263942|STEIGERWALD DOUGHERTY INC|BUILDING CONTRACTOR|2015-03-04|250
10 | |C00573519|IND|STEINKAMP|JEFFREY||ROCHESTER|VT|057670098|RETIRED|RETIRED|2015-03-31|1500
11 | |C00573519|IND|STENGEL|LINDA||SIOUX FALLS|SD|571058110|RETIRED|RETIRED|2015-03-30|250
12 | |C00573519|IND|STENSETHER|BARBARA|L|TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500
13 | |C00573519|IND|STENSETHER|JOHN||TURLOCK|CA|953821415|RETIRED|RETIRED|2015-03-11|500
14 | |C00573519|IND|STEWARDSON|MELINDA||BUFFALO GAP|TX|795082140|WYLIE INDEPENDENT SCHOOL DISTRICT|READING TEACHER|2015-03-31|250
15 | |C00573519|IND|STOCKSTILL|JAMES||PICAYUNE|MS|394665552|RETIRED|RETIRED|2015-03-04|250
16 | |C00573519|IND|STODDARD|CHERYL||FREDERICKSBURG|VA|224052180|ANTHEM|REGIONAL MANAGER|2015-03-31|250
17 | |C00573519|IND|STOKER|RICHARD||MIAMI BEACH|FL|331417401|RETIRED|RETIRED|2015-03-24|300
18 | |C00573519|IND|THORNTON|JOE||DALLAS|TX|752254816|HFF|REAL ESTATE CAPITAL MARKETS|2015-03-05|2700
19 | |C00573519|IND|TIMBLE|JAMES||FRANKLIN GROVE|IL|610319555|RETIRED|RETIRED|2015-03-28|250
20 | |C00573519|IND|TOBB|RONALD||BROOKEVILLE|MD|208333208|BOWLES FLUIDICS|OPERATIONS VP|2015-03-03|250
21 | |C00573519|IND|TOLLAKSON|DARLENE|M|SOUTH WAYNE|WI|535879761|||2015-03-30|400
22 | |C00573519|IND|TOMANN|DON||BUFFALO|MN|553134253|UMC INC.|BUSINESS OWNER/PROFESSIONAL|2015-03-03|250
23 | |C00573519|IND|TORRENCE|DARREN||PENSACOLA|FL|325075234|SELF-EMPLOYED|OWNER|2015-03-18|250
24 | |C00573519|IND|TORRE|THOMAS||CUMMING|GA|300411205|AT&T|ENGINEER|2015-03-23|250
25 | |C00573519|IND|TRAN|VINCENT||CRESCENT CITY|CA|955319576|STATE OF CALIFORNIA|DENTIST|2015-03-04|1000
26 | |C00574624|IND|CHOATE|CHARLIE||BURLESON|TX|760282217|SELF EMPLOYED|SMALL BUSINESS OWNER|2015-03-31|250
27 | |C00574624|IND|CHOR|MARLENE||ANACONDA|MT|597112904|||2015-03-31|500
28 | |C00574624|IND|MACDONALD|LENNA|R|DANIEL ISLAND|SC|294927523|BVCC LLC|ENTREPRENEUR|2015-03-25|1000
29 | |C00574624|IND|MACH|STEVEN|P|HOUSTON|TX|772190630|MACH INDUSTRIAL GROUP LP|VP FINANCE|2015-03-23|2700
30 | |C00574624|IND|MACKEY|WILLIAM||MIAMI|FL|331566023|||2015-03-31|500
31 | |C00574624|IND|MADDOX|MATTHEW|MATT|HOUSTON|TX|770083017|BROTHERS ALVARADO; P.C.|ATTORNEY|2015-03-30|1000
32 | |C00574624|IND|MADSON|RYAN||EL DORADO HILLS|CA|957629665|NA|N/A|2015-03-28|1000
33 | |C00574624|IND|MAGGLOS|LINDA||MALIBU|CA|902653746|HOMEMAKER|HOMEMAKER|2015-03-24|1000
34 | |C00574624|IND|MAGNESS|SOPHIE||HOUSTON|TX|770571814|MAGNESS ORTHODONTICS|DIRECTOR OF MARKETING|2015-03-23|500
35 | |C00574624|IND|MALONEY|THOMAS||HAMPTON BAYS|NY|119462826|SHINNECOCK HARDWARE|OWNER|2015-03-25|1000
36 | |C00574624|IND|MANN|JODI||STUDIO CITY|CA|916043855|GJ SULLIVAN|BROKER|2015-03-24|1000
37 | |C00574624|IND|MANN|KEN||STUDIO CITY|CA|916043855|COVERX|INSURANCE|2015-03-24|1000
38 | |C00574624|IND|MANN|RICHARD|F|PONTE VEDRA BEACH|FL|320824609|RETIRED|RETIRED|2015-03-31|200
39 | |C00574624|IND|MANNING|JOHN|OWEN|AUSTIN|TX|787315848|GREAT POINT CAPITAL|TRADER|2015-03-31|5400
40 | |C00574624|IND|HARDY|LONNIE||SHREVEPORT|LA|711192503|SELF EMPLOYED|CPA|2015-03-23|1000
41 | |C00574624|IND|MARACCHINI|CHRIS||CEDAR HILL|TX|751041003|AMERICAN AIRLINES|PILOT|2015-03-24|1000
42 | |C00574624|IND|MARDIGIAN|DAVID||BLOOMFIELD HILLS|MI|483040934|MCM MANAGEMENT CORPORATION|CEO|2015-03-31|5400
43 | |C00574624|IND|HARDAWAY|MIKE||MCKINNEY|TX|750706221|RAYTHEON COMPANY|TECH WRITER/EDITOR|2015-03-24|500
44 | |C00574624|IND|HARIPRASAD|SATISH||EAST STROUDSBURG|PA|183027984|SELF EMPLOYED|PRINTER|2015-03-24|500
45 | |C00574624|IND|HARPER|JIM||BIRMINGHAM|MI|480091311|RETIRED|RETIRED|2015-03-24|1000
46 | |C00574624|IND|HARRELL|KEITH||MCKINNEY|TX|750717390|BUSINESS OWNER|COUNSELOR/RESTAURANT OWNER|2015-03-25|5400
47 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|5400
48 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|-2700
49 | |C00574624|IND|JANES|RALPH||MARBLE FALLS|TX|786544071|RE JANES GRAVEL COMPNAY|CONSULTANT|2015-03-31|2700
50 | |C00458844|IND|IRIZARRY|STEVEN||WASHINGTON|DC|200041008|ROBERTI+WHITE LLC|CONSULTANT|2014-12-22|2500
51 | |C00458844|IND|SIMMONS|ANNETTE|C|DALLAS|TX|752402620|HOMEMAKER|HOMEMAKER|2014-12-17|5000
52 | |C00458844|IND|MANTENA|RAMA|R|JUPITER|FL|334774202|P4 HEALTHCARE|CEO|2014-11-19|5000
53 | |C00458844|IND|REUS|SANDRA||DORAL|FL|331783787|SUNSHINE GASOLINE|EXECUTIVE|2014-12-19|9600
54 | |C00458844|IND|PATTEN|CAROLYN|A|PORT SAINT LUCIE|FL|349863252|UNIVERSITY OF FLORIDA||2015-02-17|250
55 | |C00458844|IND|PETHOKOUKIS|JOHN|MR|WESTERN SPRINGS|IL|605582013|MORGAN STANLEY|FINANCIAL ADVISOR|2015-02-25|1000
56 | |C00458844|IND|PETHOKOUKIS|SARA||WESTERN SPRINGS|IL|605582013|HOMEMAKER|HOMEMAKER|2015-02-25|1000
57 | |C00458844|IND|PLOMARITIS|TITUS|MR|PELHAM|NH|030765003|RETIRED|RETIRED|2015-03-31|1000
58 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|5000
59 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|-2300
60 | |C00458844|IND|REPLOGLE|STEPHEN||WASHINGTON|DC|200172912|COVE STRATEGIES|CONSULTANT|2015-02-09|2300
61 | |C00577130|IND|HOLZHAUER|FRED||NOVATO|CA|949471909|METHOD PRODUCTS, PBC|CHEMIST|2015-06-30|250
62 | |C00577130|IND|HONG|PENELOPE||ROCKPORT|TX|783823610|NOT EMPLOYED|RETIRED|2015-06-30|250
63 | |C00577130|IND|WYATT|EDNA||SANTA FE|NM|875012242|SELF-EMPLOYED|CARPENTER|2015-05-20|300
64 | |C00577130|IND|YOUNKIN|RANDY||YOUNGSTOWN|OH|445052563|||2015-05-20|500
65 | |C00577130|IND|SHEWFELT|MATTHEW||LOS ANGELES|CA|900263322|WILSHIRE ESCROW COMPANY|ESCROW OFFICER|2015-06-18|250
66 | |C00577130|IND|ROTHNER|GLENN||PASADENA|CA|911052720|ROTHNER, SEGALL & GREENSTONE|ATTORNEY|2015-06-18|250
67 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400
68 | |C00577130|IND|SMITH|PRENTISS|CHARLES|BRATTLEBORO|VT|053014232|PRENTISS SMITH & CO,. INC.|INVESTMENT MANAGER|2015-06-18|400
69 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300
70 | |C00577130|IND|STRATTON|RICHARD|G|BUFFALO|NY|142163417|NICHOLS SCHOOL|TEACHER|2015-06-18|300
71 | |C00577130|IND|KAST|RICHARD||BURLINGTON|VT|054082544|SELF-EMPLOYED|PHYSICIAN|2015-06-18|212
72 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200
73 | |C00577130|IND|KUSNERZ|PEGGY|ANN|ANN ARBOR|MI|481044303|||2015-06-18|200
74 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250
75 | |C00577130|IND|MARSH|PAUL|G|HAMILTON|OH|450139476|||2015-06-18|250
76 | |C00577130|IND|MCDANIEL|MICHAEL|J|SAN DIEGO|CA|921082806|SELF|MD|2015-06-18|200
77 | |C00577130|IND|ALLEN|BRUCE||LAUGHLIN|NV|890280673|SELF-EMPLOYED|CLINICAL PSYCHOLOGIST|2015-06-02|2700
78 | |C00577130|IND|ALLEN|YOKO||LAUGHLIN|NV|890280673|N/A|HOMEMAKER|2015-06-02|2700
79 | |C00577130|IND|ROBERTSON|JOAN|R|MILWAUKEE|WI|532174340|||2015-06-10|1000
80 | |C00577130|IND|MURRAY|BRIAN||LOS ANGELES|CA|900344551|SHEPPARD MULLIN LLP|ATTORNEY|2015-06-18|250
81 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500
82 | |C00577130|IND|OWENS|BONNIE|L|NAPERVILLE|IL|605648987|RETIRED|FINANCE DIRECTOR, LOCAL GOVERNMENT|2015-06-18|500
83 | |C00577130|IND|PAUL|JANE||LOS ANGELES|CA|900662840|ANTIOCH UNIVERSITY|TEACHER|2015-06-18|250
84 | |C00577130|IND|PRUITT|GRETA||LA CRESCENTA|CA|912141541|NOT EMPLOYED|RETIRED|2015-06-18|250
85 | |C00577130|IND|PULICE|MICHAEL||LOS ANGELES|CA|900683128|HOUSEBLEND MEDIA|PRODUCTION ASSISTANT|2015-06-18|250
86 | |C00580100|IND|ANDALORO|JIM||MARBLEHEAD|MA|01945|METAL TRONICS, INC.|OWNER|2015-06-30|500
87 | |C00580100|IND|ANTON|FRANCINE||SPRING LAKE|MI|49456|RETIRED|RETIRED|2015-06-24|250
88 | |C00580100|IND|ATKINS|LORI||SAN ANTONIO|TX|78231|TEXAS SINUS CENTER|PHYSICIAN ASSISTANT|2015-06-20|250
89 | |C00580100|IND|BINGHAM|RON||JACKSON|TN|38305|EMG CLINIS OF TENNESSEE|MD|2015-06-19|500
90 | |C00580100|IND|BLUE|JAN||HUNTINGTON BEACH|CA|92648|HOAG HEALTH|SENIOR VICE PRESIDENT|2015-06-17|500
91 | |C00580100|IND|BRIDGES|PAMELA||LAUREL|MS|39443|INTERNATIONAL FIRE|PRESIDENT|2015-06-26|250
92 | |C00580100|IND|BYRNES|JECOAH||COLORADO SPRINGS|CO|80920|EMBREE CAPITAL MARKETS GROUP, INC.|SALES|2015-06-16|250
93 | |C00580100|IND|CANNON|WANDA||BEVERLY HILLS|CA|90210|RETIRED|RETIRED|2015-06-16|250
94 | |C00580100|IND|CARRERAS|DENNIS||COCONUT CREEK|FL|33073|BERSTONE PAYMENT SYSTEMS, LLC|CEO|2015-06-17|250
95 | |C00580100|IND|CARTER|SCOTT||LUBBOCK|TX|79407|OTTO'S GRANARY|MANAGER/OWNER|2015-06-19|250
96 | |C00580100|IND|CHAMPION|STEPHAN||DESTIN|FL|32541|AC LEGG|SALES|2015-06-17|250
97 | |C00580100|IND|COOKINGHAM|GAIL||ROCHESTER HILLS|MI|48307|SELF-EMPLOYED|PHYSICIAN|2015-06-30|250
98 | |C00580100|IND|CRAICHY|KINSEY||TAMPA|FL|33601|LIVING FUEL|CEO|2015-06-29|250
99 | |C00580100|IND|CRUME|W|HAYDEN|COLUMBUS|MS|39705|RETIRED|RETIRED|2015-06-16|2700
100 | |C00580100|IND|CRUMPLER|MARK||ASHDOWN|AR|71822|DOMTAR|MECHANIC|2015-06-29|250
101 | |C00580100|IND|CUGINI|CHRISTY||NAPLES|FL|34119|MILLENIUM|PHYSICIAN|2015-06-25|250
102 | |C00580100|IND|MCGEORGE|EDWARD||RICHMOND|VA|23238|MCGEORGE ROLLING HILLS RV|CEO|2015-06-26|2700
103 | |C00580100|IND|MCKAY|THOMAS||AUSTIN|TX|78720|TOM'S WAY INC.|MACHINIST|2015-06-22|250
104 | |C00580100|IND|MCNERNEY|MICHAEL||SAN PEDRO|CA|90731|MCNERNEY'S, INC|FUNERAL SERVICE PROVIDER|2015-06-18|500
105 | |C00580100|IND|MCPHERSON|EDWARD||LOS ANGELES|CA|90057|SELF-EMPLOYED|PHYSICIAN|2015-06-21|250
106 | |C00580100|IND|MORE|MICHAEL||MARLBOROUGH|MA|01752|TJX|INFRASTRUCTURE ENGINEER III|2015-06-25|350
107 | |C00580100|IND|PERSSON|ALFRED||HEMET|CA|92545|CAB CHRISTIAN INC|CEO|2015-06-16|250
108 | |C00580100|IND|NEW|JOSEPH||CARROLLTON|GA|30116|BARNES VAN LINES|CEO|2015-06-17|250
109 | |C00580100|IND|NEWMAN|PAMELA||NEW YORK|NY|10017|AON RISK SERVICES|EXECUTIVE|2015-06-01|2700
110 | |C00580100|IND|NICKELL|JERRY||AUBREY|TX|76227|SELF-EMPLOYED|CONSULTANT|2015-06-29|250
111 | |C00575795|IND|LOMBARDO|MICHAEL||SHERMAN OAKS|CA|914035345|HBO|TELEVISION EXECUTIVE|2015-04-27|2700
112 | |C00575795|IND|STAFFORD|AMANDA||MCLEAN|VA|221021431|N/A|RETIRED|2015-04-28|2700
113 | |C00575795|IND|WHITAKER|DAVID||FAYETTEVILLE|AR|727011611|SELF-EMPLOYED|ATTORNEY|2015-05-07|201
114 | |C00575795|IND|LIM|TIM||WASHINGTON|DC|200094582|PRECISION NETWORK|PRESIDENT|2015-04-12|250
115 | |C00575795|IND|GEIGER|MARC||LOS ANGELES|CA|900691401|WILLIAM MORRIS ENDEAVOR|AGENT / HEAD OF MUSIC|2015-05-01|2700
116 | |C00575795|IND|HAMILTON|JOHN||DALLAS|TX|752143452|AS MANAGEMENT|REAL ESTATE|2015-05-07|2700
117 | |C00575795|IND|WALLER|KATHY||ATLANTA|GA|303271800|THE COCA-COLA COMPANY|CFO|2015-04-28|2700
118 | |C00575795|IND|WINGENS|GARY||LIVINGSTON|NJ|070393424|LOWENSTEIN SANDLER LLP|ATTORNEY|2015-04-17|2700
119 | |C00575795|IND|EDINGTON|PATRICIA||MOBILE|AL|366022006|SELF-EMPLOYED|ANTIQUES APPRAISER|2015-04-13|500
120 | |C00575795|IND|ALFERNESS|JOY||SAN FRANCISCO|CA|941072734|NOT EMPLOYED|HUMANITARIAN|2015-05-02|1700
121 | |C00575795|IND|FLYNN|JOHN||VIENNA|VA|221816131|N/A|RETIRED|2015-05-14|500
122 | |C00575795|IND|KASSAN|ALEX||NEW YORK|NY|10013|ANCHORAGE MEDIA GROUP|PRODUCTION|2015-04-28|2700
123 | |C00575795|IND|SENATORE|BRAD||BOSTON|MA|021162671|SELF-EMPLOYED|FASHION DESIGN|2015-06-30|1000
124 | |C00575795|IND|HELLER TRIPENY|MARY||CORNING|NY|148309481|SELF-EMPLOYED||2015-05-08|2700
125 | |C00575795|IND|FINKEL|JUDITH||HOUSTON|TX|770245404|N/A|RETIRED|2015-06-01|2700
126 | |C00575795|IND|FORD|ARLENE||BALTIMORE|MD|212101526|N/A|RETIRED|2015-06-19|300
127 | |C00575795|IND|NEWMAN|MELISSA||ALEXANDRIA|VA|223142414|CENTURYLINK|ATTORNEY|2015-04-20|1000
128 | |C00575795|IND|CANTU|ALONZO||MCALLEN|TX|785042202|CANTU CONSTRUCTION & DEVELOPMENT|OWNER/DEVELOPER|2015-06-30|2700
129 | |C00575795|IND|HARRIS|MAYA||NEW YORK|NY|100366812|HILLARY FOR AMERICA|SENIOR POLICY ADVISOR|2015-06-30|2700
130 | |C00575795|IND|OTTINGER|BARBARA||PASADENA|CA|911051342|||2015-05-13|250
131 | |C00575795|IND|HAIRSTON|JAMES||NEWARK|NJ|071121708|N/A|RETIRED|2015-04-30|225
132 | |C00575795|IND|ELLISON|CARL||NEW YORK|NY|101281248|N/A|RETIRED|2015-06-23|2700
133 | |C00575795|IND|MARDIROSSIAN|SHANT||KATONAH|NY|105362919|KOHLBERG & CO., LLC|PARTNER AND COO|2015-06-28|2700
134 | |C00575795|IND|RATNER|TAWNY||CLEVELAND HEIGHTS|OH|441063138|||2015-04-26|2700
135 | |C00575795|IND|LINDEN|MARTHA||ANCHORAGE|AK|995073970|OWEN R. BELL, MD, APC|CERTIFIED NURSE MIDWIFE|2015-04-13|250
136 | |C00581876|IND|DEMLER|JOHN||NORTHFIELD|IL|600933117|RETIRED|SALES|2015-09-29|500
137 | |C00581876|IND|HUMPHREY|GORDON||CHICHESTER|NH|032586102|RETIRED|RETIRED|2015-09-29|2700
138 | |C00581876|IND|PELLEGRINO|BOB||CINCINNATI|OH|452433220|RETIRED|INVESTOR|2015-09-29|250
139 | |C00581876|IND|BOND|JAMES|D|FARGO|ND|581047058|COLLINS & COMPANY|EXECUTIVE|2015-09-29|250
140 | |C00581876|IND|PALAFOUTAS|JUDITH||ALEXANDRIA|VA|223144761|GEORGETOWN UNIVERSITY|RESEARCH DIRECTOR|2015-09-29|1000
141 | |C00581876|IND|WINSLOW|CLARK||BELVEDERE TIBURON|CA|949202426|WINSLOW CAPITAL|INVESTMENT MGMT|2015-09-29|1000
142 | |C00581876|IND|YOUNG|STEWART||WASHINGTON|DC|200024489|CORLEY CONSULTING|LOBBYIST|2015-09-29|250
143 | |C00581876|IND|BATTOCLETTI|DAVID||COLUMBUS|OH|432157513|ICE MILLER WHITEBOARD|LOBBYIST|2015-09-29|1000
144 | |C00581876|IND|COLEMAN|GEORGE||FAIRFIELD|CT|068245649|CREDIT SUISSE|BANKER|2015-09-29|500
145 | |C00581876|IND|SWALDO|THEODORE||NORTH CANTON|OH|447208807|RETIRED|RETIRED|2015-09-29|250
146 | |C00581876|IND|OSTERTHALER|ROBERT||VIENNA|VA|221821368|RETIRED|CEO|2015-09-29|900
147 | |C00581876|IND|BERGAN|PHILIP||CHARLESTON|SC|294012403|RETIRED|RETIRED|2015-09-29|500
148 | |C00581876|IND|DUBRAVCIC|STEPHEN||BRONWOOD|GA|398260083|DARKOTECH, INC|MANAGER|2015-08-07|250
149 | |C00581876|IND|BRISTOW|JULIE||CINCINNATI|OH|452083332|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700
150 | |C00581876|IND|WASSERSTROM|ALAN||COLUMBUS|OH|432072167|WASSERSTROM COMPANIES|CEO|2015-08-07|2700
151 | |C00581876|IND|SANDRIDGE|RHONDA|L|WESTFIELD CENTER|OH|442519801|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-07|2700
152 | |C00581876|IND|WILSON|RONALD||SOLON|OH|441395077|GENERAL ELECTRIC|GENERAL MANAGER|2015-08-07|500
153 | |C00581876|IND|BRISTOW|WILLIAM|S|CINCINNATI|OH|452083332|JEFF WYLER AUTOMATIVE FAMILY|PRESIDENT|2015-08-07|2700
154 | |C00581876|IND|FETTER|STEVEN||PORT TOWNSEND|WA|983683058|SELF-EMPLOYED|UTILITY CONSULTANT|2015-08-07|2700
155 | |C00581876|IND|BECHTOLD|TIMOTHY||COLUMBUS|OH|432156108|VORYS SATER|LOBBYIST|2015-08-07|500
156 | |C00581876|IND|STEWART|JENNIFER||NEW HOPE|PA|189389246|STUDENT|STUDENT|2015-08-07|250
157 | |C00581876|IND|ELSANT|MARTIN||WOODMERE|NY|115982909|NORTH SHORE HEALTH SYSTEM|RADIOLOGIST|2015-08-07|200
158 | |C00581876|IND|THOMPSON|LUCINA||DALLAS|TX|752303038|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|2700
159 | |C00581876|IND|EARL|SUSAN||COLUMBUS|OH|432061275|CIVIC VOLUNTEER|CIVIC VOLUNTEER|2015-08-17|250
160 | |C00581876|IND|MAUER|VINCENT||CINCINNATI|OH|452443604|BROCK BROWN COD|LAWYER|2015-08-18|250
161 | |C00580399|IND|COHEN|LARRY||NY|NY|100143744|SEVEN BRIDGES ADVISORS|FINANCIAL ADVISOR|2015-08-13|2700
162 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-09-03|859
163 | |C00580399|IND|COHEN|STEVE||GREENWICH|CT|068360142|POINT72 ASSET MANAGEMENT|CHAIRMAN/CEO|2015-08-15|1840
164 | |C00580399|IND|GUREGHIAN|VAHAN|H|GLADWYNE|PA|190351507|CSMI LLC|FOUNDER AND CEO|2015-09-30|2700
165 | |C00580399|IND|PJETERNIKAJ|LILA||SADDLE RIVER|NJ|074583012|||2015-08-04|1350
166 | |C00580399|IND|CONSIDINE|THOMAS||SPRING LAKE|NJ|077622369|GRAVILAUR SOLUTIONS LLC|CONSULTANT|2015-09-29|2700
167 | |C00580399|IND|CONSORTI|JASON||MONROE|NJ|088312242|CSC|IT MANAGER|2015-07-01|500
168 | |C00580399|IND|CONSTABLE|RICHARD||SOUTH ORANGE|NJ|070791141|US ATTORNEY|LAWYER/LEGAL|2015-09-09|1000
169 | |C00580399|IND|CONTI|GINA||NEW PROVIDENCE|NJ|079742117|HOMEMAKER|HOMEMAKER|2015-09-30|2500
170 | |C00580399|IND|CONTI|KURT|G|NEW PROVIDENCE|NJ|079742117|CONTI GROUP|PRESIDENT/CEO|2015-09-30|2500
171 | |C00580399|IND|CONWAY|ARTHUR|W|MAHWAH|NJ|074302040|DIALAMERICA MARKETING INC.|PRESIDENT & CEO|2015-07-16|2700
172 | |C00580399|IND|GIBBONS|MARY|M|BASKING RIDGE|NJ|079204107|ELBERON DEVELOPMENT GROUP ST. CLAIRE'|ADMINISTRATOR/SOCIAL WORKER|2015-08-20|1000
173 | |C00580399|IND|GIBLIN|BRENDON|P|SOUTHBOROUGH|MA|017721706|BRENDON PROPERTIES|DEVELOPER REAL ESTATE|2015-09-08|500
174 | |C00580399|IND|GIDWITZ|CHRISTINA||CHICAGO|IL|606065829|HOUSEWIFE|HOUSEWIFE|2015-09-27|2700
175 | |C00580399|IND|GILFILLAN|CHRISTINE|C|MORRISTOWN|NJ|079607355|THE MCJ AMELIOR FOUNDATION|PRESIDENT|2015-07-02|2700
176 | |C00580399|IND|GILFILLAN|MICHAEL|T|MADISON|NJ|079402751|BRICK CITY SPORTS CAPITAL LLC|INVESTMENTS|2015-07-02|2700
177 | |C00580399|IND|GILMAN|J|PAUL|MENDHAM|NJ|079451205|COVANTA ENERGY|SENIOR VICE PRESIDENT AND CHIEF SUSTAI|2015-07-31|2700
178 | |C00580399|IND|GILMAN|THOMAS||SCOTTSDALE|AZ|852623818|DAIMLERCHRYSLER FINANCIAL SERVICES AME|CEO|2015-07-27|2700
179 | |C00580399|IND|GILMORE|THOMAS|P|ANDOVER|NJ|078214127|GILMORE ELECTRIC INC.|ELECTRICIAN|2015-07-24|2700
180 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700
181 | |C00580399|IND|CONNORS|CHARLES|T|WESTFIELD|NJ|070902902|H&M INTERNATIONAL TRANSPORTANTION|PRESIDENT & CHIEF OPERATING OFFICER|2015-07-27|2700
182 | |C00580399|IND|CONSIGLIO|THOMAS||RAMSEY|NJ|074461346|RESOURCE REALTY|SALES|2015-08-03|2700
183 | |C00580399|IND|COLE|BRIAN||OAKLAND|NJ|074362350|COLE MEDICAL INC|VICE PRESIDENT|2015-07-01|2700
184 | |C00579458|IND|VILLARI|DAVID|J|FORT LAUDERDALE|FL|333061906|GIG INS GROUP|BUSINESS OWNER|2015-11-30|250
185 | |C00579458|IND|VIEIRA|SEAN||FAIRFAX|VA|220336226|SJV LLC|PRESIDENT|2015-11-29|1000
186 | |C00579458|IND|VIJAYANAGAR|RAGHAVENDRA||TAMPA|FL|336063573|R VIJAYANAGAR M.D. P.A.|SURGEON|2015-11-20|2000
187 | |C00579458|IND|VILLARREAL|AARON||MCALLEN|TX|785044405|||2015-10-30|2700
188 | |C00579458|IND|VILLAMIZAR|JOHN||ROYAL PALM BEACH|FL|334116107|ADVANCED VISION|OPTICIAN|2015-12-29|375
189 | |C00579458|IND|WARE|BLAKE|BEAKLEY|AMARILLO|TX|791092331|HOMEMAKER|HOMEMAKER|2015-11-19|2000
190 | |C00579458|IND|WARD|JIM||PHOENIX|AZ|850162363|THE PHOENIX SYMPHONY|CEO|2015-10-14|1000
191 | |C00579458|IND|WARD|JOHN|M|DALLAS|TX|752047849|RETIRED|RETIRED|2015-11-09|1000
192 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|4000
193 | |C00579458|IND|WARE|PATRICK|O'NEILL|AMARILLO|TX|791092331|STUDENT|STUDENT|2015-11-19|-2000
194 | |C00579458|IND|WAREHAM|KRISTINA||LAKE HIAWATHA|NJ|070342209|PRECISION CASTPARTS CORP|ENGINEER|2015-12-31|1000
195 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|-2700
196 | |C00579458|IND|ANDREWS|BARRY|G|DALLAS|TX|752052805|ANDREWS DISTRIBUTING|EXECUTIVE|2015-12-15|2700
197 | |C00579458|IND|MANNING|RALPH|F|MARS|PA|160462633|TUCKER ARENSBERG PC|ATTORNEY|2015-11-10|1000
198 | |C00579458|IND|MANNING|RAMON||HOUSTON|TX|770211611|PARTNERS ENERGY|INVESTOR|2015-10-28|250
199 | |C00579458|IND|MANNING|SAM|BLAGDEN|DALLAS|TX|752195220|SELF-EMPLOYED|INVESTMENTS|2015-11-10|500
200 | |C00579458|IND|MANRIQUE|FRANCISCO||DORAL|FL|331783505|||2015-10-20|500
201 |
--------------------------------------------------------------------------------
/NICAR2016/part1/data/famous_donors.txt:
--------------------------------------------------------------------------------
1 | C00575795|A|Q2|P|201509039001608655|15|IND|BUFFETT, WARREN|OMAHA|NE|681313311|BERKSHIRE HATHAWAY|CHAIRMAN|04152015|2700||C51337|1024052|||4090920151249626621
2 | C00577130|N|Q2|P|201507159000153383|15E|IND|RUFFALO, MARK|NEW YORK|NY|100031526|SELF-EMPLOYED|ACTOR|06022015|250|C00401224|VPF7BDV8BV8|1015044||* EARMARKED CONTRIBUTION: SEE BELOW|4071620151247172334
3 | C00458844|A|Q2|G|201510159003030910|22Y|IND|ADELSON, SHELDON|LAS VEGAS|NV|89145|||06122015|2600||GENREF0042|1029436|||4102120151256390199
4 |
--------------------------------------------------------------------------------
/NICAR2016/part1/data/scripts/utility/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'people'
--------------------------------------------------------------------------------
/NICAR2016/part1/data/scripts/utility/filter_contribs.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'csv'
4 |
5 | committee_ids = []
6 | CSV.foreach('candidates.txt', :headers => true, :col_sep => '|', :quote_char => "\x00") do |row|
7 | committee_ids << row[0]
8 | end
9 |
10 | skips = ['C00577981', 'C00578757', 'C00577312', 'C00575449', 'C00578658']
11 | used = committee_ids - skips
12 |
13 | included = {}
14 | used.each {|id| included[id] = 0}
15 |
16 | CSV.foreach('itcont.txt', :col_sep => '|', :quote_char => "\x00") do |row|
17 | #skip if not a contrib
18 | next if row[5] != '15'
19 | committee_id = row[0]
20 | if used.include? committee_id
21 | if included[committee_id] < 25
22 | puts row.to_csv(:col_sep => '|')
23 | included[committee_id] += 1
24 | else
25 | used.delete committee_id
26 | break if used.length == 0
27 | end
28 | end
29 | end
30 |
31 |
32 | exit
33 | #####
34 | ## Check the number of contributors per candidate
35 | #####
36 | committee_counts = {}
37 | committee_ids.each do |id|
38 | committee_counts[id] = 0
39 | end
40 |
41 |
42 | committee_ids.each do |id|
43 | CSV.foreach('contributors.txt', :col_sep => '|', :quote_char => "\x00") do |row|
44 | committee_counts[id] += 1 if row[0] == id
45 | end
46 | end
47 |
48 | puts committee_counts
49 |
--------------------------------------------------------------------------------
/NICAR2016/part1/data/scripts/utility/fix_names.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'csv'
4 | require 'people'
5 |
6 | np = People::NameParser.new(:case_mode => 'upper')
7 | CSV.foreach('contributors.txt', :col_sep => '|', :quote_char => "\x00") do |row|
8 | no_title = row[7].gsub(/ (MR.|MRS.|DR.|MS.)$/, '')
9 | name = np.parse(no_title)
10 | next if name[:last].empty?
11 | date_parts = row[13].match(/(\d\d)(\d\d)(\d\d\d\d)/)
12 | date_string = "#{date_parts[3]}-#{date_parts[1]}-#{date_parts[2]}"
13 | puts [name[:last], name[:first], name[:middle], row[8], row[9], row[10], row[11], row[12], date_string, row[14], row[0]].to_csv(:col_sep => '|', :quote_char => "\x00")
14 | end
15 |
--------------------------------------------------------------------------------
/NICAR2016/part1/images/create_contributions_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/create_contributions_table.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/customize-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/customize-menu.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/execute_sql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/execute_sql.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/ff-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/ff-menu.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/import.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/import.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/import_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/import_icon.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/new_database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/new_database.png
--------------------------------------------------------------------------------
/NICAR2016/part1/images/new_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part1/images/new_table.png
--------------------------------------------------------------------------------
/NICAR2016/part1/part1_steps.html:
--------------------------------------------------------------------------------
1 | A Quick Introduction to SQL Using SQLite (Just the Steps)
2 | 1. Open Firefox and click on the menu icon:
3 | 
4 | Use the "customize" option to find the SQLite Manager Plugin:
5 | 
6 | You can add it to your menu by dragging or right-click to add it to the toolbar.
7 |
8 | 2. Create a new database called campaign_finance:
9 | 
10 |
11 | 3. Create a new table called contributions (
) and give it the following field definitions:
12 | 
13 |
14 | Inserting data manually (Don't worry, you won't do this often.)
15 | 4. Insert a row of data.
16 | Use the "Execute SQL" tab (it's in the second menu row, under the icons)
17 | 
18 | And paste or type the following statement:
19 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name, city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','BUFFETT','WARREN','','OMAHA','Nebraska','68131','BERKSHIRE HATHAWAY','CHAIRMAN','2015-04-15',2700);
20 |
21 | 5. Insert three more rows (one at a time or all at once)
22 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00577130','IND','RUFFALO','MARK','','NEW YORK','NY','|100031526','SELF-EMPLOYED','ACTOR','2015-06-02',250);
23 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00458844','IND','ADELSON','SHELDON','','LAS VEGAS','NV','89145','','','2015-06-12',2600);
24 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00579458','IND','MANNING','PEYTON MR.','','CLEVELAND','OH','441141717','DENVER BRONCOS','PROFESSIONAL ATHLETE','2015-08-04',2700);
25 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','COPPOLA','SOFIA','','NEW YORK','NY','100130778','SELF-EMPLOYED','DIRECTOR/WRITER/ACTOR','2016-01-22',2700);
26 |
27 | The SELECT statement
28 | 6. Select everything from the contributions table:
29 | SELECT * FROM contributions;
30 | Note the wildcard * character.
31 |
32 | 7. Choose some fields to select:
33 | SELECT city, state FROM contributions;
34 | Note the duplicates; why are they there?
35 |
36 | 8. Get a distinct set of cities and states:
37 | SELECT DISTINCT city, state FROM contributions;
38 |
39 | THE WHERE CLAUSE
40 | 9. Add some conditions to the SELECT:
41 | SELECT * from contributions WHERE state='NY';
42 | Now try playing around with some of the operators:
43 |
44 |
45 |
46 | operator |
47 | description |
48 |
49 |
50 | = |
51 | Equal |
52 |
53 |
54 | <> |
55 | Not equal* |
56 |
57 |
58 | > |
59 | Greater than |
60 |
61 |
62 | < |
63 | Less than |
64 |
65 |
66 | >= |
67 | Greater than or equal |
68 |
69 |
70 | <= |
71 | Less than or equal |
72 |
73 |
74 |
75 | Here are some examples:
76 | SELECT * from contributions WHERE amount > 500;
77 | SELECT * from contributions WHERE amount >= 500;
78 | SELECT last_name from contributions WHERE state <> 'NY';
79 |
80 | 10. Combine conditions with AND or OR:
81 | Find only the big spenders from New York
82 | SELECT * FROM contributions WHERE city = 'NEW YORK' AND amount > 2000;
83 | Find any big spender and anyone from New York
84 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR amount > 2000;
85 |
86 | 11. But watch out for operator precedence
87 | Looking for big spenders from Las Vegas and New York City
88 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR city = 'LAS VEGAS' AND amount > 2000;
89 | How did Mark Ruffalo sneak in there?
90 | Try that again:
91 | SELECT * FROM contributions WHERE (city = 'NEW YORK' OR city = 'LAS VEGAS') AND amount > 2000;
92 |
93 | Pick One: Using BETWEEN
and IN
(NOT IN
)
94 | 11. Find all contributions between $500 and $1000
95 | SELECT * FROM contributions WHERE amount BETWEEN 251 AND 2699;
96 | (Note: this query returns the same results as SELECT * FROM contributors WHERE amount >= 500 AND amount <= 1000;
-- but it's much more readable.)
97 |
98 | 12. Find all contributors from a list of states:
99 | SELECT * from contributions WHERE state IN ('OH', 'NY');
100 | (Note: A compound statement could accomplish this same goal: state = 'OH' OR state = 'NY'
101 | But the IN
syntax makes things much clearer, and it's easier to write.)
102 |
103 | 13. Use NOT IN
to find results where a value is not included in the given set:
104 | SELECT * FROM contributions WHERE state NOT IN ('NY', 'OH');
105 |
106 | Sorting the results
107 | 14. Use ORDER BY to sort:
108 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount;
109 | And reverse the order:
110 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount DESC;
111 | And order by more than one column:
112 | SELECT state, last_name, amount FROM contributions ORDER BY state, amount DESC;
113 |
114 | Limiting the number of rows returned
115 | 15. Return only the top two contributions:
116 | SELECT * FROM contributions ORDER BY amount DESC LIMIT 2;
117 |
118 | Changing values with UPDATE
119 | 16. Check the list of state names again:
120 | SELECT state FROM contributions;
121 | Let's correct Nebraska:
122 | UPDATE contributions SET state = 'NE' WHERE state = 'Nebraska';
123 | And check again:
124 | SELECT DISTINCT state FROM contributions;
125 |
126 | DELETING rows
127 | 17. Let's get rid of a row:
128 | SELECT * FROM contributions WHERE id = 1;
129 | DELETE FROM contributions WHERE id = 1;
130 |
131 | Importing data from a flat file
132 | 18. Import a delimited file:
133 | a. Go to https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt (Or grab it from the conference computer.)
134 | b. Save the file as "contributions.txt" somewhere you can find it (your desktop is a good place).
135 | c. Click the SQLite Manager Import Wizard icon (
).
136 |
137 | - Using the Select File button, browse for the contributions.txt file you just saved.
138 | - Check the "First row contains column names" check box.
139 | - Select Pipe(|) for "Fields separated by"
140 | - For everything else, you can keep the default selections.
141 | - You should have 204 rows of data.
142 |
143 |
--------------------------------------------------------------------------------
/NICAR2016/part1/part1_steps.textile:
--------------------------------------------------------------------------------
1 | h2. A Quick Introduction to SQL Using SQLite (Just the Steps)
2 |
3 | 1. Open Firefox and click on the menu icon:
4 |
5 | !./images/ff-menu.png!
6 |
7 | Use the "customize" option to find the SQLite Manager Plugin:
8 |
9 | !./images/customize-menu.png!
10 |
11 | You can add it to your menu by dragging or right-click to add it to the toolbar.
12 |
13 |
14 |
15 | 2. Create a new database called campaign_finance:
16 |
17 | !./images/new_database.png!
18 |
19 |
20 |
21 | 3. Create a new table called contributions (!./images/new_table.png!) and give it the following field definitions:
22 |
23 | !./images/create_contributions_table.png!
24 |
25 |
26 |
27 | h3. Inserting data manually (Don't worry, you won't do this often.)
28 |
29 | 4. Insert a row of data.
30 |
31 | Use the "Execute SQL" tab (it's in the second menu row, under the icons)
32 | !./images/execute_sql.png!
33 |
34 | And paste or type the following statement:
35 |
36 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name, city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','BUFFETT','WARREN','','OMAHA','Nebraska','68131','BERKSHIRE HATHAWAY','CHAIRMAN','2015-04-15',2700);
37 |
38 |
39 |
40 |
41 | 5. Insert three more rows (one at a time or all at once)
42 |
43 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00577130','IND','RUFFALO','MARK','','NEW YORK','NY','|100031526','SELF-EMPLOYED','ACTOR','2015-06-02',250);
44 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00458844','IND','ADELSON','SHELDON','','LAS VEGAS','NV','89145','','','2015-06-12',2600);
45 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00579458','IND','MANNING','PEYTON MR.','','CLEVELAND','OH','441141717','DENVER BRONCOS','PROFESSIONAL ATHLETE','2015-08-04',2700);
46 | INSERT INTO contributions (committee_id, entity_type, last_name, first_name, middle_name,city, state, zip_code, employer, occupation, date, amount) VALUES ('C00575795','IND','COPPOLA','SOFIA','','NEW YORK','NY','100130778','SELF-EMPLOYED','DIRECTOR/WRITER/ACTOR','2016-01-22',2700);
47 |
48 |
49 |
50 |
51 |
52 | h3. The SELECT statement
53 |
54 | 6. Select everything from the contributions table:
55 |
56 | SELECT * FROM contributions;
57 |
58 | Note the wildcard * character.
59 |
60 |
61 |
62 | 7. Choose some fields to select:
63 |
64 | SELECT city, state FROM contributions;
65 |
66 | Note the duplicates; why are they there?
67 |
68 |
69 |
70 | 8. Get a distinct set of cities and states:
71 |
72 | SELECT DISTINCT city, state FROM contributions;
73 |
74 |
75 |
76 | h3. THE WHERE CLAUSE
77 |
78 | 9. Add some conditions to the SELECT:
79 | SELECT * from contributions WHERE state='NY';
80 | Now try playing around with some of the operators:
81 |
82 | |*operator*|*description*|
83 | |=|Equal|
84 | |<>|Not equal*|
85 | |>|Greater than|
86 | |<|Less than|
87 | |>=|Greater than or equal|
88 | |<=|Less than or equal|
89 |
90 | Here are some examples:
91 | SELECT * from contributions WHERE amount > 500;
92 | SELECT * from contributions WHERE amount >= 500;
93 | SELECT last_name from contributions WHERE state <> 'NY';
94 |
95 |
96 |
97 | 10. Combine conditions with AND or OR:
98 |
99 | Find only the big spenders from New York
100 | SELECT * FROM contributions WHERE city = 'NEW YORK' AND amount > 2000;
101 |
102 | Find any big spender and anyone from New York
103 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR amount > 2000;
104 |
105 |
106 |
107 | 11. But watch out for operator precedence
108 |
109 | Looking for big spenders from Las Vegas and New York City
110 | SELECT * FROM contributions WHERE city = 'NEW YORK' OR city = 'LAS VEGAS' AND amount > 2000;
111 |
112 | How did Mark Ruffalo sneak in there?
113 |
114 | Try that again:
115 | SELECT * FROM contributions WHERE (city = 'NEW YORK' OR city = 'LAS VEGAS') AND amount > 2000;
116 |
117 |
118 |
119 | h3. Pick One: Using BETWEEN
and IN
(NOT IN
)
120 |
121 | 11. Find all contributions between $500 and $1000
122 | SELECT * FROM contributions WHERE amount BETWEEN 251 AND 2699;
123 | (Note: this query returns the same results as SELECT * FROM contributors WHERE amount >= 500 AND amount <= 1000;
-- but it's much more readable.)
124 |
125 |
126 |
127 | 12. Find all contributors from a list of states:
128 | SELECT * from contributions WHERE state IN ('OH', 'NY');
129 |
130 | (Note: A compound statement could accomplish this same goal: state = 'OH' OR state = 'NY'
131 | But the IN
syntax makes things much clearer, and it's easier to write.)
132 |
133 |
134 |
135 | 13. Use NOT IN
to find results where a value is not included in the given set:
136 | SELECT * FROM contributions WHERE state NOT IN ('NY', 'OH');
137 |
138 |
139 |
140 |
141 |
142 | h3. Sorting the results
143 |
144 | 14. Use ORDER BY to sort:
145 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount;
146 | And reverse the order:
147 | SELECT last_name, amount FROM contributions WHERE amount > 250 ORDER BY amount DESC;
148 | And order by more than one column:
149 | SELECT state, last_name, amount FROM contributions ORDER BY state, amount DESC;
150 |
151 |
152 |
153 | h3. Limiting the number of rows returned
154 |
155 | 15. Return only the top two contributions:
156 | SELECT * FROM contributions ORDER BY amount DESC LIMIT 2;
157 |
158 |
159 |
160 | h3. Changing values with UPDATE
161 |
162 | 16. Check the list of state names again:
163 | SELECT state FROM contributions;
164 |
165 | Let's correct Nebraska:
166 | UPDATE contributions SET state = 'NE' WHERE state = 'Nebraska';
167 |
168 | And check again:
169 | SELECT DISTINCT state FROM contributions;
170 |
171 |
172 |
173 |
174 | h3. DELETING rows
175 |
176 | 17. Let's get rid of a row:
177 | SELECT * FROM contributions WHERE id = 1;
178 | DELETE FROM contributions WHERE id = 1;
179 |
180 |
181 |
182 |
183 |
184 |
185 | h3. Importing data from a flat file
186 |
187 | 18. Import a delimited file:
188 | a. Go to ["https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt":https://raw.githubusercontent.com/tthibo/SQL-Tutorial/master/NICAR2016/part1/data/contributions.txt] (Or grab it from the conference computer.)
189 |
190 | b. Save the file as "contributions.txt" somewhere you can find it (your desktop is a good place).
191 |
192 | c. Click the SQLite Manager Import Wizard icon (!./images/import_icon.png!).
193 |
194 | * Using the **Select File** button, browse for the **contributions.txt** file you just saved.
195 | * Check the "First row contains column names" check box.
196 | * Select **Pipe(|)** for "Fields separated by"
197 | * For everything else, you can keep the default selections.
198 | * You should have 204 rows of data.
199 |
200 |
--------------------------------------------------------------------------------
/NICAR2016/part3/data/candidates.txt:
--------------------------------------------------------------------------------
1 | id|committee_id|last_name|first_name|middle_name|party
2 | 1|C00580100|TRUMP|DONALD|J|REP
3 | 2|C00574624|CRUZ|RAFAEL "TED"|EDWARD|REP
4 | 3|C00458844|RUBIO|MARCO||REP
5 | 4|C00581876|KASICH|JOHN|R|REP
6 | 5|C00573519|CARSON|BENJAMIN|S|REP
7 | 6|C00577130|SANDERS|BERNARD||DEM
8 | 7|C00575795|CLINTON|HILLARY|RODHAM|DEM
9 | 8|C00578658|O'MALLEY|MARTIN|JOSEPH|DEM
10 | 9|C00579458|BUSH|JEB||REP
11 | 10|C00580399|CHRISTIE|CHRISTOPHER|J|REP
12 | 11|C00575449|PAUL|RAND||REP
13 | 12|C00577312|FIORINA|CARLY||REP
14 | 13|C00578757|GRAHAM|LINDSEY|O|REP
15 | 14|C00577981|HUCKABEE|MIKE||REP
16 |
--------------------------------------------------------------------------------
/NICAR2016/part3/images/ff-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part3/images/ff-menu.png
--------------------------------------------------------------------------------
/NICAR2016/part3/images/import_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part3/images/import_icon.png
--------------------------------------------------------------------------------
/NICAR2016/part3/images/new_database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/NICAR2016/part3/images/new_database.png
--------------------------------------------------------------------------------
/NICAR2016/part3/part3_steps.html:
--------------------------------------------------------------------------------
1 | SQLite III: Subqueries and Joins in SQLite
2 | 1. Open Firefox and the SQLite Manager Plugin
3 | 
4 |
5 | 2. Create a new database called contributions_candidates
6 | 
7 |
8 | 3. Use a CREATE TABLE statement to create a new table for candidate data:
9 |
10 | CREATE TABLE "candidates" (
11 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
12 | "committee_id" VARCHAR,
13 | "first_name" VARCHAR,
14 | "last_name" VARCHAR,
15 | "middle_name" VARCHAR,
16 | "party" VARCHAR
17 | );
18 |
19 |
20 | 4. Use the SQLite Manager Import Wizard (
) to import candidates.txt
21 | Remember to select the pipe delimiter ("|") and to check the box indicating that the first row contains headers.
22 |
23 | 5. Use a CREATE TABLE statement to create a new contributions table:
24 | CREATE TABLE "contributions" (
25 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
26 | "committee_id" VARCHAR,
27 | "entity_type" VARCHAR,
28 | "last_name" VARCHAR,
29 | "first_name" VARCHAR,
30 | "middle_name" VARCHAR,
31 | "city" VARCHAR,
32 | "state" VARCHAR,
33 | "zip_code" VARCHAR,
34 | "employer" VARCHAR,
35 | "occupation" VARCHAR,
36 | "date" DATETIME,
37 | "amount" INTEGER,
38 | "candidate_id" INTEGER NOT NULL,
39 | FOREIGN KEY(candidate_id) REFERENCES candidates(id)
40 | );
41 |
42 | 6. Use the SQLite Manager Import Wizard (
) to import contributions.txt:
43 |
44 | Using Subqueries
45 | 7. Find out the maxiumum contribution amount in the data set and see which contributors have given this amount.
46 | First, determine the maximum amount contriubuted:
47 | SELECT MAX (amount) FROM contributions;
48 | Then SELECT all fields for any contribution at that amount . . . but how?
49 | Like this?
50 | SELECT * FROM contributions WHERE amount = MAX (amount);
51 | Nope.
52 | Hardcode the amount?
53 | SELECT * FROM contributions WHERE amount = 5400;
54 | But what if next month the max changes? How can we make this dynamic?
55 | Subqueries to the rescue:
56 | SELECT * FROM contributions WHERE amount = (SELECT MAX(amount) FROM contributions);
57 |
58 | 8. Write a query that gets the sum amount of the top 20 contributions
59 | SELECT SUM(amount) FROM contributions WHERE id IN (SELECT id FROM contributions ORDER BY amount DESC LIMIT 20);
60 |
61 | Using a subquery on another table
62 | 9. Find all of the contributions to Hillary Clinton
63 | SELECT * FROM contributions WHERE candidate_id = (SELECT id from candidates WHERE last_name = 'CLINTON' AND first_name = 'HILLARY');
64 |
65 | Joins: Queries across tables
66 | 10. It is possible to do an implicit join simply by defining the relationship between the two tables in the WHERE
clause:
67 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions, candidates WHERE contributions.candidate_id = candidates.id;
68 |
69 | 11. Use table name aliases to save typing:
70 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a, candidates b WHERE a.candidate_id = b.id;
71 | This query returns the same results as the one above, but it saves some typing by making "a" an alias for "contributions" and "b" an alias for "candidates." The alias can use any valid table name you
72 | like, but obviously shorter aliases will save more typing, while longer ones may make the intention of the query easier to understand.
73 |
74 | Explicit JOIN
syntax
75 | 12. Rewrite the above query using explicit JOIN syntax:
76 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions JOIN candidates ON contributions.candidate_id = candidates.id;
77 |
78 | 13. Use aliases work with JOIN
syntax:
79 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id;
80 |
81 | 14. Get the number of contributions for each candidate
82 | SELECT count(a.id), b.id, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
83 | Our list of candidates seems to be coming up short. Let's check it:
84 | SELECT DISTINCT id, last_name FROM candidates;
85 | Definitely missing candidates. What happened?
86 | Performing the JOIN
returns the same results as the query with this clause: WHERE contributions.candidate_id = candidates.id
.
87 | What if a candidate has no contributions? Then that candidate is not returned by the query.
88 | The JOIN
acts just like the WHERE
clause and filters out any rows that don't match the condition defined.
89 | Joins that return only rows in which there is a match in both tables are known as INNER JOINs. This is often exactly the behavior you want from the join (ignore any rows from either table that don't relate to a row in the other table). So by default, the JOIN
keyword executes an INNER JOIN
. You can also explicitly request an INNER JOIN
, just to make things clearer:
90 | SELECT count(a.id), b.id, b.last_name FROM contributions a INNER JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
91 | The results will be the same.
92 |
93 | OUTER JOINS
94 |
95 | - A
LEFT OUTER JOIN
includes all rows from the table on the left side of the statement and only matching rows from the table on the right side of the statement.
96 | - A
RIGHT OUTER JOIN
includes all rows from the table on the right side of the statement and only matching rows from the left side of the statement.
97 | - A
FULL OUTER JOIN
includes all rows from both tables.
98 |
99 | Currently, SQLite only supports LEFT OUTER JOIN
from the list above, but some other database management systems support the other two types as well.
100 | 15. Get the number of contributions for each candidate, including those with no contributions:
101 | SELECT candidates.last_name, count(contributions.id)
102 | FROM candidates LEFT OUTER JOIN contributions
103 | ON candidates.id = contributions.candidate_id
104 | GROUP BY candidates.id, candidates.last_name
105 | ORDER BY count(contributions.id);
106 | (Note: Aliases would work here as well.)
107 |
--------------------------------------------------------------------------------
/NICAR2016/part3/part3_steps.textile:
--------------------------------------------------------------------------------
1 | h2. SQLite III: Subqueries and Joins in SQLite
2 |
3 | 1. Open Firefox and the SQLite Manager Plugin
4 | !./images/ff-menu.png!
5 |
6 |
7 |
8 | 2. Create a new database called contributions_candidates
9 |
10 | !./images/new_database.png!
11 |
12 |
13 |
14 | 3. Use a CREATE TABLE statement to create a new table for candidate data:
15 |
16 |
17 | CREATE TABLE "candidates" (
18 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
19 | "committee_id" VARCHAR,
20 | "first_name" VARCHAR,
21 | "last_name" VARCHAR,
22 | "middle_name" VARCHAR,
23 | "party" VARCHAR
24 | );
25 |
26 |
27 |
28 |
29 |
30 | 4. Use the SQLite Manager Import Wizard (!./images/import_icon.png!) to import candidates.txt
31 |
32 | Remember to select the pipe delimiter ("|") and to check the box indicating that the first row contains headers.
33 |
34 |
35 |
36 | 5. Use a CREATE TABLE statement to create a new contributions table:
37 |
38 |
39 | CREATE TABLE "contributions" (
40 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
41 | "committee_id" VARCHAR,
42 | "entity_type" VARCHAR,
43 | "last_name" VARCHAR,
44 | "first_name" VARCHAR,
45 | "middle_name" VARCHAR,
46 | "city" VARCHAR,
47 | "state" VARCHAR,
48 | "zip_code" VARCHAR,
49 | "employer" VARCHAR,
50 | "occupation" VARCHAR,
51 | "date" DATETIME,
52 | "amount" INTEGER,
53 | "candidate_id" INTEGER NOT NULL,
54 | FOREIGN KEY(candidate_id) REFERENCES candidates(id)
55 | );
56 |
57 |
58 |
59 |
60 | 6. Use the SQLite Manager Import Wizard (!./images/import_icon.png!) to import contributions.txt:
61 |
62 |
63 |
64 | h3. Using Subqueries
65 |
66 | 7. Find out the maxiumum contribution amount in the data set and see which contributors have given this amount.
67 |
68 | First, determine the maximum amount contriubuted:
69 | SELECT MAX(amount) FROM contributions;
70 |
71 | Then SELECT all fields for any contribution at that amount . . . but how?
72 |
73 | Like this?
74 | SELECT * FROM contributions WHERE amount = MAX(amount);
75 |
76 | Nope.
77 |
78 | Hardcode the amount?
79 | SELECT * FROM contributions WHERE amount = 5400;
80 |
81 | But what if next month the max changes? How can we make this dynamic?
82 |
83 | Subqueries to the rescue:
84 | SELECT * FROM contributions WHERE amount = (SELECT MAX(amount) FROM contributions);
85 |
86 |
87 |
88 |
89 | 8. Write a query that gets the sum amount of the top 20 contributions
90 |
91 | SELECT SUM(amount) FROM contributions WHERE id IN (SELECT id FROM contributions ORDER BY amount DESC LIMIT 20);
92 |
93 |
94 |
95 |
96 | h3. Using a subquery on another table
97 |
98 | 9. Find all of the contributions to Hillary Clinton
99 |
100 | SELECT * FROM contributions WHERE candidate_id = (SELECT id from candidates WHERE last_name = 'CLINTON' AND first_name = 'HILLARY');
101 |
102 |
103 |
104 |
105 | h3. Joins: Queries across tables
106 |
107 | 10. It is possible to do an *implicit* join simply by defining the relationship between the two tables in the WHERE
clause:
108 |
109 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions, candidates WHERE contributions.candidate_id = candidates.id;
110 |
111 |
112 |
113 | 11. Use table name aliases to save typing:
114 |
115 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a, candidates b WHERE a.candidate_id = b.id;
116 |
117 | This query returns the same results as the one above, but it saves some typing by making "a" an alias for "contributions" and "b" an alias for "candidates." The alias can use any valid table name you
118 | like, but obviously shorter aliases will save more typing, while longer ones may make the intention of the query easier to understand.
119 |
120 |
121 |
122 | h4. Explicit JOIN
syntax
123 |
124 | 12. Rewrite the above query using explicit JOIN syntax:
125 | SELECT contributions.last_name, contributions.first_name, candidates.last_name FROM contributions JOIN candidates ON contributions.candidate_id = candidates.id;
126 |
127 |
128 |
129 | 13. Use aliases work with JOIN
syntax:
130 | SELECT a.last_name, a.first_name, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id;
131 |
132 |
133 |
134 | 14. Get the number of contributions for each candidate
135 | SELECT count(a.id), b.id, b.last_name FROM contributions a JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
136 |
137 | Our list of candidates seems to be coming up short. Let's check it:
138 |
139 | SELECT DISTINCT id, last_name FROM candidates;
140 |
141 | Definitely missing candidates. What happened?
142 |
143 | Performing the JOIN
returns the same results as the query with this clause: WHERE contributions.candidate_id = candidates.id
.
144 |
145 | What if a candidate has no contributions? Then that candidate is not returned by the query.
146 |
147 | The JOIN
acts just like the WHERE
clause and filters out any rows that don't match the condition defined.
148 |
149 | Joins that return only rows in which there is a match in both tables are known as *INNER JOINs*. This is often exactly the behavior you want from the join (ignore any rows from either table that don't relate to a row in the other table). So by default, the JOIN
keyword executes an INNER JOIN
. You can also explicitly request an INNER JOIN
, just to make things clearer:
150 |
151 | SELECT count(a.id), b.id, b.last_name FROM contributions a INNER JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
152 |
153 | The results will be the same.
154 |
155 |
156 |
157 | h3. OUTER JOINS
158 |
159 | * A LEFT OUTER JOIN
includes all rows from the table on the left side of the statement and only matching rows from the table on the right side of the statement.
160 | * A RIGHT OUTER JOIN
includes all rows from the table on the right side of the statement and only matching rows from the left side of the statement.
161 | * A FULL OUTER JOIN
includes all rows from both tables.
162 |
163 | Currently, SQLite only supports LEFT OUTER JOIN
from the list above, but some other database management systems support the other two types as well.
164 |
165 | 15. Get the number of contributions for each candidate, including those with no contributions:
166 |
167 | SELECT candidates.last_name, count(contributions.id)
168 | FROM candidates LEFT OUTER JOIN contributions
169 | ON candidates.id = contributions.candidate_id
170 | GROUP BY candidates.id, candidates.last_name
171 | ORDER BY count(contributions.id);
172 |
173 |
174 | (Note: Aliases would work here as well.)
175 |
176 |
--------------------------------------------------------------------------------
/NICAR2016/part3/sql_scripts/create_candidates.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE "candidates" (
2 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
3 | "committee_id" VARCHAR,
4 | "first_name" VARCHAR,
5 | "last_name" VARCHAR,
6 | "middle_name" VARCHAR,
7 | "party" VARCHAR)
8 | ;
--------------------------------------------------------------------------------
/NICAR2016/part3/sql_scripts/create_contributions.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE "contributions" (
2 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
3 | "committee_id" VARCHAR,
4 | "entity_type" VARCHAR,
5 | "last_name" VARCHAR,
6 | "first_name" VARCHAR,
7 | "middle_name" VARCHAR,
8 | "city" VARCHAR,
9 | "state" VARCHAR,
10 | "zip_code" VARCHAR,
11 | "employer" VARCHAR,
12 | "occupation" VARCHAR,
13 | "date" DATETIME,
14 | "amount" INTEGER,
15 | "candidate_id" INTEGER NOT NULL,
16 | FOREIGN KEY(candidate_id) REFERENCES candidates(id)
17 | );
--------------------------------------------------------------------------------
/quick_steps.textile:
--------------------------------------------------------------------------------
1 | h2. A Quick Introduction to SQL Using SQLite (Just the Steps)
2 |
3 | 1. Open Firefox and find the SQLite Manager Plugin in the tools menu:
4 |
5 | !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/sqlite_manager_ff.png!
6 | 2. Create a new database called "contributions":
7 | !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/new_database.png!
8 |
9 | 3. Create a new table called "contributors" (!https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/new_table.png!) and give it the following field definitions:
10 | !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/create_table.png!
11 |
12 | 4. Insert a row of data:
13 | Use the "Execute SQL" tab (it's in the second menu row, under the icons): !https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/execute_sql.png!
14 |
15 |
16 | INSERT INTO contributors (last_name, first_name, city, state, zip, amount) VALUES ('Buffet', 'Warren', 'Omaha', 'Nebraska', '68101', 1500);
17 |
18 | 5. Insert three more rows (one at a time or all at once)
19 |
20 | INSERT INTO contributors (last_name, first_name, city, state, zip, amount) VALUES ('Winfrey', 'Oprah', 'Chicago', 'IL', '60601', 500);
21 | INSERT INTO contributors (last_name, first_name, city, state, zip, amount) VALUES ('Chambers', 'Anne Cox', 'Atlanta', 'GA', '30301', 200);
22 | INSERT INTO contributors (last_name, first_name, city, state, zip, amount) VALUES ('Cathy', 'S. Truett', 'Atlanta', 'GA', '30301', 1200);
23 |
24 |
25 | 6. Select everything from the contributors table:
26 | SELECT * FROM contributors;
27 |
28 | 7. Choose some fields to select:
29 | SELECT city, state FROM contributors;
30 |
31 | 8. Get a distinct set of cities and states:
32 | SELECT DISTINCT city, state FROM contributors;
33 |
34 | 9. Add some conditions to the SELECT:
35 | SELECT * from contributors WHERE state='GA';
36 | Now try playing around with some of the operators:
37 |
38 | |*operator*|*description*|
39 | |=|Equal|
40 | |<>|Not equal*|
41 | |>|Greater than|
42 | |<|Less than|
43 | |>=|Greater than or equal|
44 | |<=|Less than or equal|
45 |
46 | Here are some examples:
47 | SELECT * from contributors WHERE amount > 1200;
48 | SELECT * from contributors WHERE amount >= 1200;
49 | SELECT last_name from contributors WHERE state <> 'GA';
50 |
51 | 10. Combine conditions with AND or OR:
52 | SELECT * FROM contributors WHERE state = 'GA' AND amount > 1000;
53 | SELECT * FROM contributors WHERE state = 'GA' OR amount > 1000;
54 |
55 | 11. But watch out for operator precedence:
56 | SELECT * FROM contributors WHERE city = 'Chicago' OR state = 'GA' AND amount > 1000;
57 | How did Oprah sneak in there?
58 | Try that again:
59 | SELECT * FROM contributors WHERE (city = 'Chicago' OR state = 'GA') AND amount > 1000;
60 |
61 | 12. Order the results:
62 | SELECT last_name, amount FROM contributors WHERE amount > 200 ORDER BY amount;
63 | And reverse the order:
64 | SELECT last_name, amount FROM contributors WHERE amount > 200 ORDER BY amount DESC;
65 | And order by more than one column:
66 | SELECT last_name, state, amount FROM contributors ORDER BY state, amount DESC;
67 |
68 | 13. Return only the top two contributors:
69 | SELECT * FROM CONTRIBUTORS ORDER BY amount DESC LIMIT 2;
70 |
71 |
72 | h3. Importing data from a flat file
73 |
74 | 14. Import a delimited file:
75 | a. Go to ["https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/contributors.txt":https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/contributors.txt]
76 |
77 | b. Save the file as "contributors.txt" somewhere you can find it (your desktop is a good place).
78 |
79 | c. Click the SQLite Manager Import Wizard icon (!https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/import_icon.png!).
80 |
81 | * Using the **Select File** button, browse for the **contributors.txt** file you just saved.
82 | * Check the "First row contains column names" check box.
83 | * Select **Pipe(|)** for "Fields separated by"
84 | * For everything else, you can keep the default selections.
85 | * You should have 103 rows of data.
86 |
87 | h3. Aggregate Functions
88 |
89 | 15. Count the number of contributors from California:
90 | SELECT COUNT(id) FROM contributors WHERE state = 'CA';
91 |
92 | 16. Select the minimum and maximum contributions:
93 | SELECT MAX(amount) FROM contributors;
94 | SELECT MIN(amount) FROM contributors;
95 |
96 | 17. Add up the contributions from Georgia:
97 | SELECT SUM(amount) FROM contributors WHERE state = 'GA';
98 |
99 | 18. Find the average contribution:
100 | SELECT AVG(amount) FROM contributors;
101 |
102 | 19. Find the total amount of contributions per state:
103 | SELECT state, SUM(amount) FROM contributors GROUP BY state;
104 |
105 |
106 | 20. Find the total amount of contributions per city and state:
107 | SELECT city, state, SUM(amount) FROM contributors GROUP BY city, state;
108 | Now order cities by their total contributions:
109 | SELECT city, state, SUM(amount) FROM contributors GROUP BY city, state ORDER BY SUM(amount) DESC;
110 |
111 |
112 |
113 | 
A Gentle Introduction to SQL Using SQLite by Troy Thibodeaux is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
114 |
--------------------------------------------------------------------------------
/quick_steps2.textile:
--------------------------------------------------------------------------------
1 | h2. Quick Introduction to Data Normalization Using SQLite
2 |
3 | 1. Open Firefox and the SQLite Manager plugin.
4 |
5 | 2. Create a new database called contributors_candidates.
6 |
7 | 3. Create the *candidates* table:
8 | CREATE TABLE "candidates" ("id" INTEGER PRIMARY KEY NOT NULL, "first_name" VARCHAR NOT NULL, "last_name" VARCHAR NOT NULL , "middle_name" VARCHAR, "party" VARCHAR NOT NULL )
9 |
10 | 4. Download the text file at "https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/candidates.txt":https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/candidates.txt and import
11 | it using the Import icon (!https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/images/import_icon.png!).
12 | * Remember to check the "First row contains column names" check box.
13 | * And set the "Fields separated by" value to "Pipe (|)."
14 |
15 | 5. Create the *contributors* table, including a foreign key:
16 |
17 | CREATE TABLE "contributors" (
18 | "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
19 | "last_name" VARCHAR,
20 | "first_name" VARCHAR,
21 | "middle_name" VARCHAR,
22 | "street_1" VARCHAR,
23 | "street_2" VARCHAR,
24 | "city" VARCHAR,
25 | "state" VARCHAR,
26 | "zip" VARCHAR,
27 | "amount" INTEGER,
28 | "date" DATETIME,
29 | "candidate_id" INTEGER NOT NULL,
30 | FOREIGN KEY(candidate_id) REFERENCES candidates(id)
31 | );
32 |
33 | 6. Dowload the text file at "https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/contributors_with_candidate_id.txt":https://github.com/tthibo/SQL-Tutorial/raw/master/tutorial_files/contributors_with_candidate_id.txt and import it into the *contributors* table.
34 |
35 | 7. Use a subquery to find all contributors to Barack Obama:
36 | CREATE TABLE "candidates" ("id" INTEGER PRIMARY KEY NOT NULL, "first_name" VARCHAR NOT NULL, "last_name" VARCHAR NOT NULL , "middle_name" VARCHAR, "party" VARCHAR NOT NULL )
37 |
38 | 8. Use a *WHERE* clause to join two tables:
39 | CREATE TABLE "candidates" ("id" INTEGER PRIMARY KEY NOT NULL, "first_name" VARCHAR NOT NULL, "last_name" VARCHAR NOT NULL , "middle_name" VARCHAR, "party" VARCHAR NOT NULL )
40 |
41 | 9. Use aliases to reduce typing:
42 | SELECT a.last_name, a.first_name, b.last_name FROM contributors a, candidates b WHERE a.candidate_id = b.id;
43 |
44 | 10. Use explicit *join* syntax to join two tables:
45 | SELECT contributors.last_name, contributors.first_name, candidates.last_name FROM contributors JOIN candidates ON contributors.candidate_id = candidates.id;
46 |
47 | 11. Use aliases with explicit *join* syntax:
48 | SELECT a.last_name, a.first_name, b.last_name FROM contributors a JOIN candidates b ON a.candidate_id = b.id;
49 |
50 | 12. Count the number of contributors per candidate using a join:
51 | SELECT count(a.id), b.id, b.last_name FROM contributors a JOIN candidates b ON a.candidate_id = b.id GROUP BY b.id, b.last_name;
52 | Notice that not all candidates are included: SELECT DISTINCT id, last_name FROM candidates;
53 |
54 | 13. Rewrite the query to include all candidates, including those with no contributors:
55 | CREATE TABLE "candidates" ("id" INTEGER PRIMARY KEY NOT NULL, "first_name" VARCHAR NOT NULL, "last_name" VARCHAR NOT NULL , "middle_name" VARCHAR, "party" VARCHAR NOT NULL )
56 |
57 | 14. Use a *self-join* to look for contributions by the same contributor:
58 | SELECT a.last_name, a.first_name, a.id as 'A ID', b.id AS 'B ID', a.amount, b.amount FROM contributors a, contributors b where a.last_name = b.last_name AND a.first_name=b.first_name AND a.id < b.id;
59 |
--------------------------------------------------------------------------------
/readme.textile:
--------------------------------------------------------------------------------
1 | h2. Note: This version of the tutorial is out of date: the SQLite Manager Firefox plugin referenced is obsolete.
2 | Please check out the newer version of this tutorial being maintained by @zstumoren:
3 | https://a-gentle-introduction-to-sql.readthedocs.io/en/latest/
4 |
5 | h2. A Gentle Introduction to SQL Using SQLite
6 |
7 | "Part I":https://github.com/tthibo/SQL-Tutorial/blob/master/tutorial_files/part1.textile
8 | "Part II":https://github.com/tthibo/SQL-Tutorial/blob/master/tutorial_files/part2.textile
9 | "Part III":https://github.com/tthibo/SQL-Tutorial/blob/master/tutorial_files/part3.textile
10 |
11 | Part IV TK
12 |
13 | 
A Gentle Introduction to SQL Using SQLite by Troy Thibodeaux is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
14 |
--------------------------------------------------------------------------------
/tutorial_files/candidates.txt:
--------------------------------------------------------------------------------
1 | id|first_name|last_name|middle_name|party
2 | 33|Joseph|Biden||D
3 | 36|Samuel|Brownback||R
4 | 34|Hillary|Clinton|R.|D
5 | 39|Christopher|Dodd|J.|D
6 | 26|John|Edwards||D
7 | 22|Rudolph|Giuliani||R
8 | 24|Mike|Gravel||D
9 | 16|Mike|Huckabee||R
10 | 30|Duncan|Hunter||R
11 | 31|Dennis|Kucinich||D
12 | 37|John|McCain||R
13 | 20|Barack|Obama||D
14 | 32|Ron|Paul||R
15 | 29|Bill|Richardson||D
16 | 35|Mitt|Romney||R
17 | 38|Tom|Tancredo||R
18 | 41|Fred|Thompson|D.|R
19 |
--------------------------------------------------------------------------------
/tutorial_files/contributors.txt:
--------------------------------------------------------------------------------
1 | id|last_name|first_name|city|state|zip|amount
2 | |Helen||Washington|DC|200122649|15
3 | |Vespa|Anthony|Franklin Lakes|NJ|074172831|50
4 | |Cohen|Jared|Sandwich|MA|02563|50
5 | |Albrecht|Robert|woodbridge|VA|22192|10
6 | |Vespa|Anthony|Franklin Lakes|NJ|074172831|11
7 | |Varley|Allyson|birmingham|AL|35242|25
8 | |Norton|Billy|Denton|TX|762012519|5
9 | |Barley|Shannon|Hermosa Beach|CA|90254|10
10 | |Lermitte|A.|Bryn Athyn|PA|19009|25
11 | |Letalik|Adam|Beverly Hills|CA|90210|50
12 | |Welch|Mark|Columbia Falls|MT|599120206|2300
13 | |Welch|Sheila|Columbia Falls|MT|599120206|2300
14 | |See|Alvin B.|Southwick|MA|010770444|500
15 | |Taylor|Richard D.|Shreveport|LA|711013114|250
16 | |Trammell|Joel T.|Austin|TX|787351509|2300
17 | |Whitfield|George R.|Seoul Kore|ZZ|11070|1600
18 | |Young|Craig|Kyle|TX|786400099|500
19 | |Golobek|Donald|Wellsboro|PA|169011837|2100
20 | |Golobek|Mona|Wellsboro|PA|169011837|2100
21 | |Cutter|Kerry E.|Sacramento|CA|958643013|2100
22 | |Miller|James R.|Burtonsville|MD|208661043|2100
23 | |Muldoon|Andrew|Westfield|NJ|070903022|2100
24 | |Muldoon|Joanne|Westfield|NJ|070903022|2100
25 | |Howard|Patrick G.|Concord|NH|033022219|2100
26 | |Shudlick|Jon L.|N Ft Myers|FL|33917|500
27 | |Furber|Donna P.|Downey|CA|902402634|2100
28 | |Furber|James E.|Downey|CA|902402634|2100
29 | |Baumgardner|David|Wellington|TX|790954836|1000
30 | |Cowles|Donald K.|Los Angeles|CA|900461410|500
31 | |Young|Robert S.|Rancho Palos Verde|CA|902756342|1000
32 | |Brown|Robert J.|Shawnee Mission|KS|662243709|2100
33 | |Bucciarelli|Joseph C.|Norwalk|CT|068551110|500
34 | |Wrenn|Edgar|Las Vegas|NV|891213950|2100
35 | |Jacknow|Gerald|Austin|TX|787461638|1000
36 | |Low|John|Mountain View|CA|940434237|1000
37 | |Hommel|Jason E.|Penn Valley|CA|959469705|2300
38 | |Hallam|Robert W.|Tracy|CA|953779020|500
39 | |Geisick|Shanna|Penn Valley|CA|959469705|2300
40 | |Teasley|Harry E.|Tampa|FL|336112814|1000
41 | |Hull|Robert P.|Grafton|NH|032403439|2300
42 | |Ham|George E.|Independence|MO|640555135|2100
43 | |Messenger|Andrew L.|San Antonio|FL|335767965|2100
44 | |Messenger|Catherine|San Antonio|FL|335767965|2100
45 | |Dermer|Jeffrey D.|Atlanta|GA|303097662|500
46 | |Que|Simon|San Jose|CA|951173027|1000
47 | |Book|Everard|Englewood|FL|342244503|2100
48 | |Speicher|John M.|Geyserville|CA|954419687|1000
49 | |Coker|Ed|Edwardsville|AL|362610128|2100
50 | |Koszyk|Francis J.|Prospect Heights|IL|600701117|250
51 | |||Rocky Mount|VA|24151|500
52 | |Rodney|James M.|Southfield|MI|480755726|2100
53 | |Borst|Laura Jane|Houston|TX|770421411|1000
54 | |Bailey|Donald T.|Springfield|CO|810731420|2100
55 | |Giannone|Nick F.|Lake Jackson|TX|775661497|250
56 | |Bailey|Lloyd W.|Rocky Mount|NC|278043319|1000
57 | |Hays|Leslie C.|Alamogordo|NM|883110161|1000
58 | |Nigro|Robert S.J.|New Ringgold|PA|179609069|500
59 | |Costin|Brian M.|Schaumburg|IL|60193|250
60 | |Whitfield|George R.|Seoul Kore|ZZ|11070|500
61 | |Harrington|Eric J.|Suffield|CT|060781624|300
62 | |Willmann|Marie E.|Port Lavaca|TX|779795166|1000
63 | |Burden|Steven J|Lutz|FL|335585313|250
64 | |Hamilton|Dirk|Bryant|AR|720223949|500
65 | |Davis|Jeremy S.|Houston|TX|770252267|2300
66 | |McClellan|James M.|Sikeston|MO|63801|2100
67 | |Burrows|Donald|Zephyrhills|FL|335405728|400
68 | |Chang|Chung K.|Santa Clara|CA|950513534|1000
69 | |Whitfield|George R.|Seoul Kore|ZZ|11070|200
70 | |Offerdahl|Richard E.|Incline Village|NV|894527899|2400
71 | |Royalty|James W.|Lake Jackson|TX|775666036|500
72 | |Bullard|Darrell E.|Houston|TX|770195726|250
73 | |Cowan|Daniel F.|Galveston|TX|775515861|250
74 | |Franklin|William J.|Mesa|AZ|852057444|250
75 | |Pearlman|Howard B.|FPO AE|ZZ|096360001|250
76 | |Lengel|Thomas E.|Bastrop|TX|78602|250
77 | |Barth|George R.|Cape Coral|FL|339044462|2000
78 | |Martin|John I.|Graham|TX|764504420|250
79 | |Williams|James|Sebring|FL|338721443|250
80 | |Brueggemann|Bernard|Walton|KY|41094|250
81 | |Hansen|Donald P.|Medina|WA|980395321|250
82 | |Siemens|Abe|Rancho Mirage|CA|922703116|500
83 | |Weymer|Richard A.|George West|TX|780223587|2300
84 | |Weymer|Jean Dea|George West|TX|780223587|2300
85 | |Ellinwood|John C.|Tubac|AZ|856461445|2100
86 | |Solcher|Albert Kennedy|Katy|TX|774941824|500
87 | |Euvall|Arland|Brigham City|UT|843023721|500
88 | |Rosenlund|Jack C.|Ennis|MT|597290891|1000
89 | |Buckman|Robert F.|Elkton|MD|219217617|500
90 | |Sturdevant|William E.|Brazoria|TX|77422|1000
91 | |Scudder|Stuart B.|Lomita|CA|907173213|500
92 | |Green|Adam T.|Salt Lake City|UT|841204092|114
93 | |Reynolds|Lois C.|Bellaire|TX|774013402|1150
94 | |Cole|Joshua David|Sarasota|FL|342381508|1000
95 | |Keyston|David H.|Carmel|CA|939217066|500
96 | |Getz|Clarence D.|Helena|MT|596026535|1000
97 | |Abbott|Robert L.|Greenville|NC|278585416|250
98 | |Antosh|Jim|Shawnee|OK|748010506|250
99 | |Lewis|Donald S.|Virginia Beach|VA|234513838|250
100 | |Oden|Ray P.|Shreveport|LA|711061824|2300
101 | |Verster|Jeanette M.|Miami|FL|331431807|2300
102 |
--------------------------------------------------------------------------------
/tutorial_files/contributors_candidates.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/contributors_candidates.sqlite
--------------------------------------------------------------------------------
/tutorial_files/contributors_with_candidate_id.txt:
--------------------------------------------------------------------------------
1 | id|last_name|first_name|middle_name|street_1|street_2|city|state|zip|amount|date|candidate_id
2 | |Agee|Steven||549 Laurel Branch Road||Floyd|VA|24091|500.00|2007-06-30|16
3 | |Ahrens|Don||4034 Rennellwood Way||Pleasanton|CA|94566|250.00|2007-05-16|16
4 | |Ahrens|Don||4034 Rennellwood Way||Pleasanton|CA|94566|50.00|2007-06-18|16
5 | |Ahrens|Don||4034 Rennellwood Way||Pleasanton|CA|94566|100.00|2007-06-21|16
6 | |Akin|Charles||10187 Sugar Creek Road||Bentonville|AR|72712|100.00|2007-06-16|16
7 | |Akin|Mike||181 Baywood Lane||Monticello|AR|71655|1500.00|2007-05-18|16
8 | |Akin|Rebecca||181 Baywood Lane||Monticello|AR|71655|500.00|2007-05-18|16
9 | |Aldridge|Brittni||808 Capitol Square Place, SW||Washington|DC|20024|250.00|2007-06-06|16
10 | |Allen|John D.||1052 Cannon Mill Drive||North Augusta|SC|29860|1000.00|2007-06-11|16
11 | |Allen|John D.||1052 Cannon Mill Drive||North Augusta|SC|29860|1300.00|2007-06-29|16
12 | |Allison|John W.||P.O. Box 1089||Conway|AR|72033|1000.00|2007-05-18|16
13 | |Allison|Rebecca||3206 Summit Court||Little Rock|AR|72227|1000.00|2007-04-25|16
14 | |Allison|Rebecca||3206 Summit Court||Little Rock|AR|72227|200.00|2007-06-12|16
15 | |Altes|R.D.||8600 Moody Road||Fort Smith|AR|72903|2300.00|2007-06-21|16
16 | |Andres|Dale||1160 Glen Oaks Drive||West Des Moines|IA|50266|250.00|2007-06-06|16
17 | |Anthony|John||211 Long Island Drive||Hot Springs|AR|71913|2300.00|2007-06-12|16
18 | |Arbogast|Robert||12900 State Route 56 SE||Mount Sterling|OH|43143|500.00|2007-04-08|16
19 | |Arbogast|Robert||12900 State Route 56 SE||Mount Sterling|OH|43143|100.00|2007-06-22|16
20 | |Ardle|William||412 Dakota Avenue||Springfield|OH|45504|50.00|2007-06-28|16
21 | |Atiq|Omar||7200 S Hazel Street||Pine Bluff|AR|71603|1000.00|2007-05-18|16
22 | |Atiq|Omar||7200 S Hazel Street||Pine Bluff|AR|71603|1000.00|2007-06-27|16
23 | |Baker|David||2550 Adamsbrooke Drive||Conway|AR|72034|2300.00|2007-04-11|16
24 | |Bancroft|David||2934 Broderick Street||San Francisco|CA|94123|250.00|2007-04-24|16
25 | |Banks|Charles||P.O. Box 251310||Little Rock|AR|72225|1000.00|2007-05-14|16
26 | |Barbee|John||516 Kellyridge Drive||Apex|NC|27502|500.00|2007-05-23|16
27 | |Buckler|Steve||24351 Armada Dr||Dana Point|CA|926291306|50.00|2007-07-30|20
28 | |Buckler|Steve||24351 Armada Dr||Dana Point|CA|926291306|25.00|2007-08-16|20
29 | |Buckheit|Bruce||8904 KAREN DR||FAIRFAX|VA|220312731|100.00|2007-09-19|20
30 | |Buckel|Linda||PO Box 683130||Park City|UT|840683130|2300.00|2007-08-14|20
31 | |Buckel|Linda||PO Box 683130||Park City|UT|840683130|-2300.00|2007-08-14|20
32 | |Buckel|Linda||PO Box 683130||Park City|UT|840683130|4600.00|2007-08-14|20
33 | |Buck|Thomas||4206 Terrace Street||Kansas City|MO|64111|100.00|2007-09-25|20
34 | |Buck|Jay|K.|1855 Old Willow Rd Unit 322||Northfield|IL|600932918|200.00|2007-09-12|20
35 | |Buck|Blaine|M|45 Eaton Ave||Camden|ME|048431752|2300.00|2007-09-30|20
36 | |Buck|Barbara||1780 NE 138th St||North Miami|FL|331811316|50.00|2007-09-13|20
37 | |Buck|Barbara||1780 NE 138th St||North Miami|FL|331811316|50.00|2007-07-19|20
38 | |Buchman|Mark M||2530 Lawton Ave||San Luis Obispo|CA|934015622|460.80|2007-07-18|20
39 | |Bucher|Ida|M|1400 Warnall Ave||Los Angeles|CA|900245333|100.00|2007-07-10|20
40 | |Buchanek|Elizabeth||7917 Kentbury Dr||Bethesda|MD|208144615|50.00|2007-09-30|20
41 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|500.00|2007-09-24|20
42 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|-500.00|2007-09-24|20
43 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|500.00|2007-09-24|20
44 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|700.00|2007-08-28|20
45 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|-700.00|2007-08-28|20
46 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|1000.00|2007-08-28|20
47 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|1300.00|2007-08-09|20
48 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|200.00|2007-08-14|20
49 | |Buchanan|John||2025 NW 29th Rd||Boca Raton|FL|334316303|500.00|2007-07-25|20
50 | |Buchanan|John||4635 49th St NW||Washington|DC|200164320|200.09|2007-09-23|20
51 | |Harrison|Ryan||2247 3rd St||La Verne|CA|917504918|25.00|2007-07-26|20
52 | |BYNUM|HERBERT||332 SUNNYSIDE ROAD||TAMPA|FL|336177249|-500.00|2008-03-10|22
53 | |BYINGTON|MARGARET|E.|2633 MIDDLEBORO LANE N.E.||GRAND RAPIDS|MI|495061254|-2300.00|2008-03-03|22
54 | |BYERS|BOB|A.|13170 TELFAIR AVENUE||SYLMAR|CA|913423573|-2300.00|2008-03-07|22
55 | |BYERS|AUDREY||2658 LADBROOK WAY||THOUSAND OAKS|CA|913615073|-200.00|2008-03-07|22
56 | |BUSH|KRYSTIE||P.O. BOX 61046||DENVER|CO|802061046|-2300.00|2008-03-06|22
57 | |BUSH|ERIC||P.O. BOX 61046||DENVER|CO|802061046|-2300.00|2008-03-06|22
58 | |BURTON|SUSAN||9338 DEER CREEK DRIVE||TAMPA|FL|336472286|-2300.00|2008-03-05|22
59 | |BURTON|STEVEN|G.|9938 DEER CREEK DRIVE||TAMPA|FL|33647|-2300.00|2008-03-05|22
60 | |BURTON|GLENN|M.|4404 CHARLESTON COURT||TAMPA|FL|336092620|-2300.00|2008-03-05|22
61 | |BURKHARDT|CRAIG|S.|910 15TH STREET N.W.||WASHINGTON|DC|200052503|-500.00|2008-03-07|22
62 | |BURKHARDT|CRAIG|S.|910 15TH STREET N.W.||WASHINGTON|DC|200052503|-1000.00|2008-03-07|22
63 | |BURKHARDT|BARBARA||910 15TH STREET N.W.||WASHINGTON|DC|200052503|-500.00|2008-03-07|22
64 | |BURKE|SUZANNE|M.|3401 EVANSTON||SEATTLE|WA|981038677|-700.00|2008-03-05|22
65 | |BURKE|GAIL||165 E. 32ND STREET|APARTMENT 9E|NEW YORK|NY|100166014|-2000.00|2008-03-05|22
66 | |BURKE|DONALD|J.|12 LOMPOC||RANCHO SANTA MARGA|CA|926881817|-2300.00|2008-03-11|22
67 | |BURGERT|RONALD|L.|5723 PLUMTREE DRIVE||DALLAS|TX|752524926|-1000.00|2008-03-05|22
68 | |BULL|BARTLE|B.|439 E. 51ST STREET||NEW YORK|NY|100226473|-800.00|2008-03-10|22
69 | |BULL|BARTLE|B.|439 E. 51ST STREET||NEW YORK|NY|100226473|-1000.00|2008-03-10|22
70 | |BUKOWSKI|DANIEL|J.|702 S. WRIGHT STREET||NAPERVILLE|IL|605406736|-100.00|2008-03-10|22
71 | |BUISSON|MARGARET|A.|P.O. BOX 197029||LOUISVILLE|KY|402597029|-200.00|2008-03-11|22
72 | |BUCKLEY|WALTER|W.|1635 COUNTRY ROAD||BETHLEHEM|PA|180155718|-100.00|2008-03-05|22
73 | |BUCKLEY|MARJORIE|B.|1635 COUNTRY ROAD||BETHLEHEM|PA|180155718|-100.00|2008-03-05|22
74 | |BRUNO|JOHN||10136 WINDERMERE CHASE BLVD.||GOTHA|FL|347344707|-2300.00|2008-03-06|22
75 | |BRUNO|IRENE||10136 WINDERMERE CHASE BLVD.||GOTHA|FL|347344707|-2300.00|2008-03-06|22
76 | |BROWN|TIMOTHY|J.|26826 MARLOWE COURT||STEVENSON RANCH|CA|913811020|-2300.00|2008-03-06|22
77 | |Schuff|Bryan||1700 W Sweden Rd||Brockport|NY|14420|-25.00|2008-08-22|32
78 | |Hobbs|James||229 Cherry Lane||White House|TN|37188|-25.00|2008-08-19|32
79 | |Ranganath|Anoop||2507 Willard Drive||Charlottesville|VA|22903|-100.00|2008-04-21|32
80 | |Nystrom|Michael|A|93A Fairmont Street||Arlington|MA|02474|-503.00|2008-04-21|32
81 | |Muse|Nina|Jo|2915 Toro Canyon Rd||Austin|TX|78746|-50.00|2008-04-21|32
82 | |Waddell|James|L.|1823 Spel Lane SW||Rochester|MN|55902|-28.00|2008-04-21|32
83 | |Brucks|William|C.|PO Box 391||Corona del Mar|CA|92625|-150.00|2008-04-21|32
84 | |Kuehn|David||14502 West 93rd Street||Lenexa|KS|66215|-330.00|2008-04-21|32
85 | |Verster|Jeanette|M.|7220 SW 61st St||Miami|FL|331431807|-1000.00|2008-04-21|32
86 | |Uihlein|Richard||1396 N Waukegan Rd||Lake Forest|IL|600451147|-2300.00|2008-04-21|32
87 | |Eskenberry|Robert|P|10960 Gray Cir||Westminster|CO|80020|-223.00|2008-04-21|32
88 | |Froehling|Alan|L.|302 Broadway St||Mount Vernon|IL|628645116|-844.80|2008-04-21|32
89 | |Duryea|Marcia|A.|123 Bayview Ave||Amityville|NY|11701|-299.50|2008-04-21|32
90 | |Perreault|Louise||503 Brockridge Hunt Drive||Hampton|VA|23666|-34.08|2008-04-21|32
91 | |Rozenfeld|Timur||57 Herbert Road||Robbinsville|NJ|08691|-777.95|2008-04-21|32
92 | |Kazor|Christopher|M|707 Spindletree ave||Naperville|IL|60565|-2592.00|2008-04-21|32
93 | |Lehner|Thomas|S.|2701 Star Lane||Wadsworth|OH|44281|-200.00|2008-04-21|32
94 | |Plummer|Joseph||587 Blake Hill Rd||New Hampton|NH|032564424|-24.60|2008-04-21|32
95 | |Raught|Philip|M|4714 Plum Way||Pittsburgh|PA|15201|-1046.00|2008-04-21|32
96 | |Ferrara|Judith|D|1508 Waterford Road||Yardley|PA|19067|-1100.00|2008-04-21|32
97 | |Johnson|Cathleen|E.|1003 Justin Ln Apt 2016||Austin|TX|787572648|-14.76|2008-04-21|32
98 | |Sanford|Bradley||940 Post St #43||San Francisco|CA|94109|-24.53|2008-04-21|32
99 | |Gaarder|Bruce||PO Box 4085||Mountain Home AFB|ID|83648|-261.00|2008-04-21|32
100 | |Choe|Hyeokchan||207 Bridle Way||Fort Lee|NJ|070246302|-39.50|2008-04-21|32
101 | |Jacobs|Richard|G.|14337 Tawya Rd||Apple Valley|CA|923075545|-1000.00|2008-04-21|32
102 | |Aaronson|Rebecca||2000 Village Green Dr Apt 12||Mill Creek|WA|980125787|100.00|2008-02-08|34
103 | |Aarons|Elaine||481 Buck Island Rd Apt 17A|APT 17A|West Yarmouth|MA|026733300|25.00|2008-02-26|34
104 | |Aarons|Elaine||481 Buck Island Rd Apt 17A|APT 17A|West Yarmouth|MA|026733300|70.00|2008-02-25|34
105 | |Aarons|Elaine||481 Buck Island Rd Apt 17A|APT 17A|West Yarmouth|MA|026733300|100.00|2008-02-08|34
106 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|50.00|2008-02-29|34
107 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-29|34
108 | |Aaronson|Rebecca||2000 Village Green Dr Apt 12||Mill Creek|WA|980125787|100.00|2008-02-14|34
109 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-24|34
110 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-22|34
111 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-17|34
112 | |Reid|Elizabeth||73 W Patent Rd|OPHIR FARM NORTH|Bedford Hills|NY|105072222|-350.00|2008-08-28|34
113 | |Reich|Thomas||499 Park Ave||New York|NY|100221240|-2300.00|2008-08-28|34
114 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-08|34
115 | |Aaron|Shirley||101 Cherry Ave||Havana|FL|323331311|100.00|2008-02-03|34
116 | |Aaron|Sharron||1804 E Montgomery St||Broken Arrow|OK|740121840|500.00|2008-02-09|34
117 | |Aaron|Patricia||418 NW 35th St||Oklahoma City|OK|731188602|200.00|2008-02-26|34
118 | |Aaron|Patricia||418 NW 35th St||Oklahoma City|OK|731188602|100.00|2008-02-12|34
119 | |Aaron|Jim||2178 Fairway Cir||Canton|MI|481885097|300.00|2008-02-07|34
120 | |Aaron|Jim||2178 Fairway Cir||Canton|MI|481885097|200.00|2008-02-29|34
121 | |Aaron|Carole||PO Box 1806||Ogunquit|ME|039071806|70.00|2008-02-29|34
122 | |Aaron|Carole||PO Box 1806||Ogunquit|ME|039071806|50.00|2008-02-07|34
123 | |Aaron|Carole||PO Box 1806||Ogunquit|ME|039071806|100.00|2008-02-03|34
124 | |Aaron|Barbara||2298 Pacific Ave # 6||San Francisco|CA|941151435|1000.00|2008-02-11|34
125 | |Aanonsen|Lin||897 Raymond Ave||Saint Paul|MN|551141508|250.00|2008-02-21|34
126 | |Aanonsen|Lin||897 Raymond Ave||Saint Paul|MN|551141508|100.00|2008-02-08|34
127 | |BOURNE|TRAVIS||LAGE KAART 77||BRASSCHATT||02930|-500.00|2008-11-20|35
128 | |SECRIST|BRIAN|L.|3 MULE DEER TRAIL||LITTLETON|CO|801275722|-1000.00|2008-04-07|35
129 | |TOLLESTRUP|TRAVIS|W.|16331 WINECREEK RD.||SAN DIEGO|CA|92127|-1000.00|2008-05-15|35
130 | |ACCORD|DEAN|C.|8813 ROBINSON RIDGE ROAD||LAS VEGAS|NV|891175812|500.00|2007-07-13|35
131 | |ABTS|HENRY||P. O. BOX 7299||INCLINE VILLAGE|NV|894527299|100.00|2007-07-13|35
132 | |ABSHIER|LANNY||14191 S.E. HIGHWAY 301||SUMMERFIELD|FL|34491|500.00|2007-09-25|35
133 | |ABSHIER|DIANA||14191 S.E. HIGHWAY 301||SUMMERFIELD|FL|34491|500.00|2007-09-25|35
134 | |ABREU|KEVIN|M.|1305 GARDEN GLEN LANE||PEARLAND|TX|775816547|50.00|2007-09-30|35
135 | |ABREU|KEVIN|M.|1305 GARDEN GLEN LANE||PEARLAND|TX|775816547|150.00|2007-08-09|35
136 | |ABREU|KEVIN|M.|1305 GARDEN GLEN LANE||PEARLAND|TX|775816547|50.00|2007-07-19|35
137 | |ABRAMOWITZ|NIRA||411 HARBOR ROAD||SOUTHPORT|CT|068901376|2300.00|2007-09-14|35
138 | |ABRAMS|MICHAEL||7910 WOODMONT AVENUE||BETHESDA|MD|208143002|250.00|2007-09-29|35
139 | |ABRAMOWITZ|KEN||200 CENTRAL PARK S.|APARTMENT 31A|NEW YORK|NY|100191448|300.00|2007-09-11|35
140 | |ABOUBAKARE|NASAR||1400 SAN MIGUEL DRIVE||CORONA DEL MAR|CA|926251300|1000.00|2007-07-09|35
141 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|75.00|2007-09-25|35
142 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|25.00|2007-09-17|35
143 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|75.00|2007-08-31|35
144 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|75.00|2007-08-14|35
145 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|25.00|2007-08-06|35
146 | |ABEGG|PATRICIA|T.|1862 E. 5150 S.||SALT LAKE CITY|UT|841176911|25.00|2007-07-10|35
147 | |ABDELLA|THOMAS|M.|4231 MONUMENT WALL WAY #340||FAIRFAX|VA|220308440|50.00|2007-09-30|35
148 | |ABBOTT|WELDON|S.|777 EAST SOUTH TEMPLE 4E||SALT LAKE CITY|UT|841021269|100.00|2007-09-29|35
149 | |ABBOTT|WELDON|S.|777 EAST SOUTH TEMPLE 4E||SALT LAKE CITY|UT|841021269|50.00|2007-08-09|35
150 | |ABBOTT|GERALD|F.|389 BENEFIT STREET||PROVIDENCE|RI|029032946|100.00|2007-09-15|35
151 | |ABBOTT|GERALD|F.|389 BENEFIT STREET||PROVIDENCE|RI|029032946|100.00|2007-08-15|35
152 | |ABEDIN|ZAINUL||715 N. CENTRAL AVENUE|SUITE 212|GLENDALE|CA|912031164|500.00|2008-01-21|37
153 | |ABBOTT|SYBIL|F.|446 GAMES DRIVE||RENO|NV|895093326|75.00|2008-01-08|37
154 | |ABBOTT|SYBIL|F.|446 GAMES DRIVE||RENO|NV|895093326|50.00|2008-01-08|37
155 | |ABBOTT|RONALD|LEANDER|5453 HAWTHORNE STREET||MONTCLAIR|CA|917632551|200.00|2008-01-31|37
156 | |ABBOTT|RONALD|LEANDER|5453 HAWTHORNE STREET||MONTCLAIR|CA|917632551|100.00|2008-01-08|37
157 | |ABBOTT|ROBERT|A.|3061 LOREE ROAD||DECKERVILLE|MI|484279763|500.00|2008-01-21|37
158 | |ABBOTT|MIKE|E.|4516 OSPREY LNDG||NICEVILLE|FL|325786810|1000.00|2008-01-15|37
159 | |ABBOT|DAVID|M.|56 SALEM STREET||ANDOVER|MA|018102114|200.00|2008-01-21|37
160 | |ABBO|PAULINE|MORENCY|10720 JACOB LANE||WHITE LAKE|MI|483862274|35.00|2008-01-07|37
161 | |ABATE|MARIA|ELENA|1291 NIGHTINGALE AVENUE||MIAMI SPRINGS|FL|331663832|2600.00|2008-01-25|37
162 | |ABAIR|PETER||40 EVANS STREET||WATERTOWN|MA|024722150|25.00|2008-01-09|37
163 | |ABACHERLI|SHIRLEY|M.|29875 NEWPORT ROAD||MENIFEE|CA|925849524|150.00|2008-01-28|37
164 | |AARONS|CHARLES||1730 SHORE DRIVE||ANCHORAGE|AK|995153207|300.00|2008-01-30|37
165 | |AARONS|CHARLES||1730 SHORE DRIVE||ANCHORAGE|AK|995153207|410.00|2008-01-15|37
166 | |AARONS|CHARLES||1730 SHORE DRIVE||ANCHORAGE|AK|995153207|500.00|2008-01-09|37
167 | |ABEL|JOHN|H.|422 THOMAS STREET||BETHLEHEM|PA|180153316|200.00|2008-01-22|37
168 | |ABEL|MARLING|L.|14 HANGING MOSS LANE||GREENVILLE|SC|296155069|100.00|2008-01-22|37
169 | |ABEL|RUDOLPH||4532 OCEAN BLVD.|# 108|SARASOTA|FL|342421337|100.00|2008-01-08|37
170 | |ABELE|RODNEY||3620 METAIRIE HEIGHTS AVENUE||METAIRIE|LA|700021823|500.00|2008-01-15|37
171 | |ABERCROMBIE|DENIS||11811 WATER OAK CT||MAGNOLIA|TX|773546270|500.00|2008-01-30|37
172 | |ABESHAUS|MERRILL|M.|1801 N. HEREFORD DRIVE||FLAGSTAFF|AZ|860011121|120.00|2008-01-16|37
173 | |ABRAHAM|GEORGE||P.O. BOX 1504||LAKE CHARLES|LA|706021504|800.00|2008-01-17|37
174 | |ABRAHAMSON|PETER|J.|1030 W. ROSCOE STREET||CHICAGO|IL|606572207|50.00|2008-01-25|37
175 | |ABRAHAM|SALEM|A.|P.O. BOX 7||CANADIAN|TX|790140007|1000.00|2008-01-17|37
176 | |ABRAHAM|SALEM|A.|P.O. BOX 7||CANADIAN|TX|790140007|1300.00|2008-01-30|37
177 |
--------------------------------------------------------------------------------
/tutorial_files/images/BUFFET.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/BUFFET.png
--------------------------------------------------------------------------------
/tutorial_files/images/alabama.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/alabama.png
--------------------------------------------------------------------------------
/tutorial_files/images/alert_aggregate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/alert_aggregate.png
--------------------------------------------------------------------------------
/tutorial_files/images/amount_by_city_state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/amount_by_city_state.png
--------------------------------------------------------------------------------
/tutorial_files/images/amount_by_state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/amount_by_state.png
--------------------------------------------------------------------------------
/tutorial_files/images/and_or_sans_parens.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/and_or_sans_parens.png
--------------------------------------------------------------------------------
/tutorial_files/images/and_statment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/and_statment.png
--------------------------------------------------------------------------------
/tutorial_files/images/avg_amt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/avg_amt.png
--------------------------------------------------------------------------------
/tutorial_files/images/between.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/between.png
--------------------------------------------------------------------------------
/tutorial_files/images/browse_and_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/browse_and_search.png
--------------------------------------------------------------------------------
/tutorial_files/images/browse_candidates.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/browse_candidates.png
--------------------------------------------------------------------------------
/tutorial_files/images/browse_contributors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/browse_contributors.png
--------------------------------------------------------------------------------
/tutorial_files/images/buffet_by_id.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/buffet_by_id.png
--------------------------------------------------------------------------------
/tutorial_files/images/city_state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/city_state.png
--------------------------------------------------------------------------------
/tutorial_files/images/city_state_by_amount_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/city_state_by_amount_desc.png
--------------------------------------------------------------------------------
/tutorial_files/images/concat_city_state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/concat_city_state.png
--------------------------------------------------------------------------------
/tutorial_files/images/connect_db.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/connect_db.png
--------------------------------------------------------------------------------
/tutorial_files/images/count_ca.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/count_ca.png
--------------------------------------------------------------------------------
/tutorial_files/images/create_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/create_table.png
--------------------------------------------------------------------------------
/tutorial_files/images/delete_prep.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/delete_prep.png
--------------------------------------------------------------------------------
/tutorial_files/images/distinct_state_space.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/distinct_state_space.png
--------------------------------------------------------------------------------
/tutorial_files/images/distinct_zip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/distinct_zip.png
--------------------------------------------------------------------------------
/tutorial_files/images/execute_sql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/execute_sql.png
--------------------------------------------------------------------------------
/tutorial_files/images/first_and.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/first_and.png
--------------------------------------------------------------------------------
/tutorial_files/images/group_by_join.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/group_by_join.png
--------------------------------------------------------------------------------
/tutorial_files/images/group_by_join_results.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/group_by_join_results.png
--------------------------------------------------------------------------------
/tutorial_files/images/group_by_left_outer_join.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/group_by_left_outer_join.png
--------------------------------------------------------------------------------
/tutorial_files/images/group_by_without_city.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/group_by_without_city.png
--------------------------------------------------------------------------------
/tutorial_files/images/having_amount_greater.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/having_amount_greater.png
--------------------------------------------------------------------------------
/tutorial_files/images/import.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/import.png
--------------------------------------------------------------------------------
/tutorial_files/images/import_confirm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/import_confirm.png
--------------------------------------------------------------------------------
/tutorial_files/images/import_confirm_rows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/import_confirm_rows.png
--------------------------------------------------------------------------------
/tutorial_files/images/import_contributors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/import_contributors.png
--------------------------------------------------------------------------------
/tutorial_files/images/import_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/import_icon.png
--------------------------------------------------------------------------------
/tutorial_files/images/in.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/in.png
--------------------------------------------------------------------------------
/tutorial_files/images/is_not_null.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/is_not_null.png
--------------------------------------------------------------------------------
/tutorial_files/images/last_name_NULL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/last_name_NULL.png
--------------------------------------------------------------------------------
/tutorial_files/images/lewis_or_null.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/lewis_or_null.png
--------------------------------------------------------------------------------
/tutorial_files/images/like_initial.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/like_initial.png
--------------------------------------------------------------------------------
/tutorial_files/images/max_amount.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/max_amount.png
--------------------------------------------------------------------------------
/tutorial_files/images/multiple_joins.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/multiple_joins.png
--------------------------------------------------------------------------------
/tutorial_files/images/new_database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/new_database.png
--------------------------------------------------------------------------------
/tutorial_files/images/new_table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/new_table.png
--------------------------------------------------------------------------------
/tutorial_files/images/not_lewis.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/not_lewis.png
--------------------------------------------------------------------------------
/tutorial_files/images/open_sqlite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/open_sqlite.png
--------------------------------------------------------------------------------
/tutorial_files/images/or_statement.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/or_statement.png
--------------------------------------------------------------------------------
/tutorial_files/images/order_by.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/order_by.png
--------------------------------------------------------------------------------
/tutorial_files/images/order_by_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/order_by_desc.png
--------------------------------------------------------------------------------
/tutorial_files/images/order_by_multiple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/order_by_multiple.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_all.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_all.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_contributors_candidates_names.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_contributors_candidates_names.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_distinct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_distinct.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_distinct_lname.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_distinct_lname.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_distinct_state_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_distinct_state_normal.png
--------------------------------------------------------------------------------
/tutorial_files/images/select_substr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/select_substr.png
--------------------------------------------------------------------------------
/tutorial_files/images/self_join.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/self_join.png
--------------------------------------------------------------------------------
/tutorial_files/images/sqlite_manager_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/sqlite_manager_empty.png
--------------------------------------------------------------------------------
/tutorial_files/images/sqlite_manager_ff.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/sqlite_manager_ff.png
--------------------------------------------------------------------------------
/tutorial_files/images/sqlite_open_last_db.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/sqlite_open_last_db.png
--------------------------------------------------------------------------------
/tutorial_files/images/state_after_update.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/state_after_update.png
--------------------------------------------------------------------------------
/tutorial_files/images/state_column.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/state_column.png
--------------------------------------------------------------------------------
/tutorial_files/images/state_ga.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/state_ga.png
--------------------------------------------------------------------------------
/tutorial_files/images/subquery_max.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/subquery_max.png
--------------------------------------------------------------------------------
/tutorial_files/images/sum_ga.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/sum_ga.png
--------------------------------------------------------------------------------
/tutorial_files/images/sum_top_20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/sum_top_20.png
--------------------------------------------------------------------------------
/tutorial_files/images/tool_menu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/tool_menu.jpg
--------------------------------------------------------------------------------
/tutorial_files/images/top_twenty_contributors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/top_twenty_contributors.png
--------------------------------------------------------------------------------
/tutorial_files/images/va_contribs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/va_contribs.png
--------------------------------------------------------------------------------
/tutorial_files/images/warning_aggregate_where.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/warning_aggregate_where.png
--------------------------------------------------------------------------------
/tutorial_files/images/where_clause1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/where_clause1.png
--------------------------------------------------------------------------------
/tutorial_files/images/where_gt_2300.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/where_gt_2300.png
--------------------------------------------------------------------------------
/tutorial_files/images/where_gt_2300_with_group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/where_gt_2300_with_group.png
--------------------------------------------------------------------------------
/tutorial_files/images/where_plus_having.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/where_plus_having.png
--------------------------------------------------------------------------------
/tutorial_files/images/zip_LIKE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/images/zip_LIKE.png
--------------------------------------------------------------------------------
/tutorial_files/part4.textile:
--------------------------------------------------------------------------------
1 | h2. Changing the database:
2 |
3 | h3. SELECT INTO
4 |
5 | h3. ALTER
6 |
7 | h3. DROP
8 |
9 | h2. Optimizing queries.
10 |
11 | h3. CREATE INDEX
12 |
13 |
14 | 
A Gentle Introduction to SQL Using SQLite by Troy Thibodeaux is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
15 |
--------------------------------------------------------------------------------
/tutorial_files/sql_keywords.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250
2 | {\fonttbl\f0\fmodern\fcharset0 Courier;\f1\froman\fcharset0 Times-Roman;}
3 | {\colortbl;\red255\green255\blue255;}
4 | \margl1440\margr1440\vieww9000\viewh8400\viewkind0
5 | \deftab720
6 | \pard\pardeftab720\sa240\ql\qnatural
7 |
8 | \f0\fs24 \cf0 ADD
9 | \f1 \
10 |
11 | \f0 ALL
12 | \f1 \
13 |
14 | \f0 ALTER
15 | \f1 \
16 |
17 | \f0 AND
18 | \f1 \
19 |
20 | \f0 AS
21 | \f1 \
22 |
23 | \f0 ASC
24 | \f1 \
25 |
26 | \f0 BY
27 | \f1 \
28 |
29 | \f0 CHECK
30 | \f1 \
31 |
32 | \f0 COLUMN
33 | \f1 \
34 |
35 | \f0 CREATE
36 | \f1 \
37 |
38 | \f0 DATE
39 | \f1 \
40 |
41 | \f0 DEFAULT
42 | \f1 \
43 |
44 | \f0 DELETE
45 | \f1 \
46 |
47 | \f0 DESC
48 | \f1 \
49 |
50 | \f0 DROP
51 | \f1 \
52 |
53 | \f0 FOR
54 | \f1 \
55 |
56 | \f0 FROM
57 | \f1 \
58 |
59 | \f0 IN
60 | \f1 \
61 |
62 | \f0 INTO
63 | \f1 \
64 |
65 | \f0 IS
66 | \f1 \
67 |
68 | \f0 LIKE
69 | \f1 \
70 |
71 | \f0 NOT
72 | \f1 \
73 |
74 | \f0 NULL
75 | \f1 \
76 |
77 | \f0 ON
78 | \f1 \
79 |
80 | \f0 OR
81 | \f1 \
82 |
83 | \f0 ORDER
84 | \f1 \
85 |
86 | \f0 REVOKE
87 | \f1 \
88 |
89 | \f0 SELECT
90 | \f1 \
91 |
92 | \f0 SET
93 | \f1 \
94 |
95 | \f0 TABLE
96 | \f1 \
97 |
98 | \f0 THEN
99 | \f1 \
100 |
101 | \f0 TO
102 | \f1 \
103 |
104 | \f0 UNIQUE
105 | \f1 \
106 |
107 | \f0 UPDATE
108 | \f1 \
109 |
110 | \f0 WITH
111 | \f1 \
112 | }
--------------------------------------------------------------------------------
/tutorial_files/sql_keywords.txt:
--------------------------------------------------------------------------------
1 | SQL Data Statements:
2 | SELECT
3 | INSERT
4 | UPDATE
5 | DELETE
6 |
7 | SQL Schema Statements
8 | CREATE TABLE
9 | CREATE VIEW
10 | DROP TABLE
11 | DROP VIEW
12 | GRANT
13 | REVOKE
14 | ALTER
15 |
16 | SQL-Transaction
17 | COMMIT
18 | ROLLBACK
19 |
20 | Modifiers
21 | WHERE
22 | FROM
23 | DISTINCT
24 | IS NULL (IS NOT NULL)
25 | ORDER BY (ASC, DESC)
26 | GROUP BY
27 | HAVING
28 | AND & OR
29 | JOIN
30 | UNION
31 | IN
32 | INTO
33 | BETWEEN
34 | LIKE
35 | COUNT
36 | MAX
37 | MIN
38 | SUM
39 | LIKE
40 | AVERAGE
41 | JOIN
42 | ALIAS (AS?)
43 | OUTER JOIN
44 | CONCAT
45 | SUBSTRING
46 | TRIM
47 |
--------------------------------------------------------------------------------
/tutorial_files/sql_tutorial.txt:
--------------------------------------------------------------------------------
1 | A Gentle Introduction to SQL using SQLite
2 |
3 | SQL or Structured Query language is the language used to communicate with relational databases. What are relational databases? Well, most of the popular database systems you may know, such as MS Access, MySQL or SQLite, are all relational. That is, they all use a relational model, which, it turns out, can be described much like a spreadsheet:
4 | * Data is organized into tables (relations) that represent a collection of similar objects (e.g. contributors).
5 | * The columns of the table represent the attributes that members of the collection share (last name, home address, amount of contribution).
6 | * Each row in the table represents an individual member of the collection (one contributor).
7 | * And the fields in the row represent the attributes of that individual (Smith, 1228 Laurel St., $250).
8 |
9 | Much of the power of a relational database lies in the ability to query these relations, both within a table (give me all contributors who donated at least $500 and who live in Wyoming) and among tables (from the contributors, judges and litigants tables, give me all contributors who donated at least $1000 to Judge Crawford and who also had legal cases over which Judge Crawford presided). SQL is the powerful and rather minimalist language we use to ask such questions of our data in a relational database. How minimalist is SQL? The basic vocabulary comes down to a few main verbs:
10 |
11 | SELECT
12 | INSERT
13 | UPDATE
14 | DELETE
15 |
16 | I imagine you can guess what each of those verbs does, even if you've never written a database query.
17 | To create and change tables in the database, there are a few other verbs to use:
18 |
19 | CREATE
20 | DROP
21 | ALTER
22 |
23 | Those are the keyword verbs for almost everything you need to do. The language also includes a number of modifiers that help specify the action of the verbs, but the core list comes down to a couple dozen words. These basic keywords are common across pretty much all relational databases. A specific database management system (Access, MySQL or SQLite) may add its own extensions to the common keywords, but the lion's share of the work is done with this handful of words, and they're basically the same across database applications.
24 |
25 | By combining these simple keywords, you can create remarkably complex and specific queries. And the basic syntax still reads fairly clearly:
26 | SELECT last_name FROM contributors WHERE state = 'WY';
27 |
28 | The SQL query above reads pretty much like the English sentence for the same request: "Select the last name from the contributors table for all contributors whose state is WY." If you're using a graphical interface for Access or another database, that interface is simply constructing queries like these behind the scenes. So, why not
29 | take command of your queries and write them yourself?
30 |
31 | So, let's dive in. For this tutorial, we will be using SQLite, a free and open source database manager that's lightweight and portable.
32 |
33 | DO WE HAVE TO INSTALL SINCE WE'RE USING FIREFOX SQLITE MANAGER?
34 | First, we have to install SQLite.
35 |
36 | For Mac:
37 | If you're using a Mac with OS X 10.5 Leopard or newer, do nothing. It's already installed.
38 | Open up your Terminal (here's how), and type 'which sqlite3'.
39 | You should see the path to SQLite 3, which looks something like this: /usr/local/bin/sqlite3.
40 | Now test the SQLite command prompt. Type 'sqlite3'. You should see something like this:
41 |
42 | SQLite version 3.6.22
43 | Enter ".help" for instructions
44 | Enter SQL statements terminated with a ";"
45 | sqlite>
46 |
47 | For PC:
48 | First you will need to download two files from the SQLite web site:
49 | 1) Go to http://www.sqlite.org/download.html
50 | 2) Under the ‘Precompiled Binaries For Windows’ section, download these two files:
51 |
52 | sqlite-3_6_23.zip (214.32 KiB)
53 | A command-line program for accessing and modifing SQLite databases.
54 | See the documentation for additional information.
55 |
56 | sqlitedll-3_6_23.zip (213.17 KiB)
57 | This is a DLL of the SQLite library without the TCL bindings.
58 | The only external dependency is MSVCRT.DLL.
59 |
60 | Download the zip files to C:\Program Files (Technically, you just need to download these files to somewhere your system can find them; any folder defined in the system PATH will do).
61 |
62 | 3) Unzip the files. (If you do not have WinZip or another Zip archive extractor on your system, then you may need to download one, such as Aladdin Expander: http://download.cnet.com/Aladdin-Expander/3000-2250_4-2931968.html.)
63 |
64 | 4) Inside the unzipped sqlite-3_6_23, you should find sqlite3.exe. Click on that file, and you should see a black box pop up with something like
65 | SQLite version 3.6.22
66 | Enter ".help" for instructions
67 | Enter SQL statements terminated with a ";"
68 | sqlite>
69 |
70 | At this point you have done all the configuration and installation you need to do for SQLite. Taxing, I know.
71 | You are looking at a command-line interface for SQLite. You can type all of your SQL commands here, and eventually you may want to. But we're going to use a different interface to get started. If you want to check out the command-line interface, type ".help" and see what's there. When you're ready, go ahead and exit from that prompt
72 | by typing ".exit". Close the Terminal window for Mac or the command console for Windows.
73 |
74 |
75 | Install the SQLite Manager Firefox Plugin
76 | Go to https://addons.mozilla.org/en-US/firefox/addon/5817 and click Add to Firefox.
77 | Click Install Now.
78 | Restart Firefox.
79 | In the Tools menu, you should find the SQLite Manager: [screen shot]
80 | Clicking that item should bring up the manager. It's a simple interface for creating and interacting
81 | with your SQLite databases.
82 |
83 |
84 | Creating the First Database
85 | Mousing over each of the icons at the top of the SQLite Manager tool will show what the icon does.
86 | To create a database, simply click on the icon for "New Database" [screen shot]
87 | Name the database "test" and save it anywhere you like (the desktop will work, or your documents folder).
88 |
89 | Creating a Table
90 | Click the "New Table" icon, and you'll get a form allowing you to create a new table.
91 | To create a table, we have to define the attributes or columns it contains. For each column, we define the
92 | datatype of the data it will contain. Define the columns as follows: [screen shot]
93 |
94 | Name the table "contributors."
95 | The id field will be a unique identifier for each contributor (and therefore will be the "Primary Key" for the row). It will be an integer that will automatically increment with each row we add, and it cannot be null or empty (because we need it as the unique identifier.
96 |
97 | The next three columns will all contain text strings of undetermined lengths (last names, for example, come in all kinds of lengths), so we'll use the VARCHAR or "variable character" datatype.
98 |
99 | For the state and zip columns, if we know that the number of characters will always be the same (for example, 2 for state postal abbreviation), we could use the CHAR character type, rather than VARCHAR. The pros and cons of choosing between the two vary among database management systems. SQLite doesn't really distinguish between the two, so we'll just use VARCHAR to keep things simple.
100 |
101 | By the way, It may seem strange that the zip column uses a VARCHAR datatype, but remember that some zips start with a 0 (00501 is in NY). So, we want to treat this column as a string of text, rather than as a number (which would be 501).
102 |
103 | Click OK, and you will see a dialogue box with the full SQL statement that the manager will execute on your database:
104 | CREATE TABLE "contributors" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "last_name" VARCHAR, "first_name" VARCHAR, "city" VARCHAR, "state" VARCHAR, "zip" VARCHAR, "amount" INTEGER)
105 |
106 | The syntax should be clear, since it just reflects the choices we made in the form. Before you click OK, you can edit the SQL in the box.
107 |
108 | SQLite is not at all particular about datatypes, but most other relational databases are, so it's good practice to define the datatypes of a column in a meaningful way. In practice, if we know maximum the length of the string, as in a date or zipcode, we could define it as part of the column definition: VARCHAR(2) or VARCHAR(5).
109 |
110 |
111 | The syntax is "CREATE TABLE" followed by the
112 |
113 |
114 | http://www.firstsql.com/tutor.htm
115 | http://www.sqlite.org/lang_keywords.html
116 |
117 | SQL Data Statements:
118 | SELECT
119 | INSERT
120 | UPDATE
121 | DELETE
122 |
123 | SQL Schema Statements
124 | CREATE TABLE
125 | CREATE VIEW
126 | DROP TABLE
127 | DROP VIEW
128 | GRANT
129 | REVOKE
130 | ALTER
131 |
132 | SQL-Transaction
133 | COMMIT
134 | ROLLBACK
135 |
136 | Modifiers
137 | WHERE
138 | FROM
139 | DISTINCT
140 | IS NULL (IS NOT NULL)
141 | ORDER BY (ASC, DESC)
142 | GROUP BY
143 | HAVING
144 | AND & OR
145 | JOIN
146 | UNION
147 | IN
148 | INTO
149 | BETWEEN
150 | LIKE
151 | COUNT
152 | MAX
153 | MIN
154 | SUM
155 | LIKE
156 | AVERAGE
157 | JOIN
158 | ALIAS (AS?)
159 | OUTER JOIN
160 | CONCAT
161 | SUBSTRING
162 | TRIM
163 |
--------------------------------------------------------------------------------
/tutorial_files/sqlite_install.textile:
--------------------------------------------------------------------------------
1 | First, we have to install SQLite.
2 |
3 | For Mac:
4 | If you're using a Mac with OS X 10.5 Leopard or newer, do nothing. It's already installed.
5 | Open up your Terminal (here's how), and type 'which sqlite3'.
6 | You should see the path to SQLite 3, which looks something like this: /usr/local/bin/sqlite3.
7 | Now test the SQLite command prompt. Type 'sqlite3'. You should see something like this:
8 |
9 | SQLite version 3.6.22
10 | Enter ".help" for instructions
11 | Enter SQL statements terminated with a ";"
12 | sqlite>
13 |
14 | For PC:
15 | First you will need to download two files from the SQLite web site:
16 | 1) Go to http://www.sqlite.org/download.html
17 | 2) Under the ‘Precompiled Binaries For Windows’ section, download these two files:
18 |
19 | sqlite-3_6_23.zip (214.32 KiB)
20 | A command-line program for accessing and modifing SQLite databases.
21 | See the documentation for additional information.
22 |
23 | sqlitedll-3_6_23.zip (213.17 KiB)
24 | This is a DLL of the SQLite library without the TCL bindings.
25 | The only external dependency is MSVCRT.DLL.
26 |
27 | Download the zip files to C:\Program Files (Technically, you just need to download these files to somewhere your system can find them; any folder defined in the system PATH will do).
28 |
29 | 3) Unzip the files. (If you do not have WinZip or another Zip archive extractor on your system, then you may need to download one, such as Aladdin Expander: http://download.cnet.com/Aladdin-Expander/3000-2250_4-2931968.html.)
30 |
31 | 4) Inside the unzipped sqlite-3_6_23, you should find sqlite3.exe. Click on that file, and you should see a black box pop up with something like
32 |
33 | SQLite version 3.6.22
34 | Enter ".help" for instructions
35 | Enter SQL statements terminated with a ";"
36 | sqlite>
37 |
38 |
39 | At this point you have done all the configuration and installation you need to do for SQLite. Taxing, I know.
40 | You are looking at a command-line interface for SQLite. You can type all of your SQL commands here, and eventually you may want to. But we're going to use a different interface to get started. If you want to check out the command-line interface, type ".help" and see what's there. When you're ready, go ahead and exit from that prompt
41 | by typing ".exit". Close the Terminal window for Mac or the command console for Windows.
42 |
43 |
44 |
--------------------------------------------------------------------------------
/tutorial_files/sqlite_keywords.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250
2 | {\fonttbl\f0\froman\fcharset0 Times-Roman;}
3 | {\colortbl;\red255\green255\blue255;}
4 | \margl1440\margr1440\vieww9000\viewh8400\viewkind0
5 | \deftab720
6 | \pard\pardeftab720\ql\qnatural
7 |
8 | \f0\fs24 \cf0 ABORT\
9 | ACTION\
10 | ADD\
11 | AFTER\
12 | ALL\
13 | ALTER\
14 | ANALYZE\
15 | AND\
16 | AS\
17 | ASC\
18 | ATTACH\
19 | AUTOINCREMENT\
20 | BEFORE\
21 | BEGIN\
22 | BETWEEN\
23 | BY\
24 | CASCADE\
25 | CASE\
26 | CAST\
27 | CHECK\
28 | COLLATE\
29 | COLUMN\
30 | COMMIT\
31 | CONFLICT\
32 | CONSTRAINT\
33 | CREATE\
34 | CROSS\
35 | CURRENT_DATE\
36 | CURRENT_TIME\
37 | CURRENT_TIMESTAMP\
38 | DATABASE\
39 | DEFAULT\
40 | DEFERRABLE\
41 | DEFERRED\
42 | DELETE\
43 | DESC\
44 | DETACH\
45 | DISTINCT\
46 | DROP\
47 | EACH\
48 | ELSE\
49 | END\
50 | ESCAPE\
51 | EXCEPT\
52 | EXCLUSIVE\
53 | EXISTS\
54 | EXPLAIN\
55 | FAIL\
56 | FOR\
57 | FOREIGN\
58 | FROM\
59 | FULL\
60 | GLOB\
61 | GROUP\
62 | HAVING\
63 | IF\
64 | IGNORE\
65 | IMMEDIATE\
66 | IN\
67 | INDEX\
68 | INDEXED\
69 | INITIALLY\
70 | INNER\
71 | INSERT\
72 | INSTEAD\
73 | INTERSECT\
74 | INTO\
75 | IS\
76 | ISNULL\
77 | JOIN\
78 | KEY\
79 | LEFT\
80 | LIKE\
81 | LIMIT\
82 | MATCH\
83 | NATURAL\
84 | NO\
85 | NOT\
86 | NOTNULL\
87 | NULL\
88 | OF\
89 | OFFSET\
90 | ON\
91 | OR\
92 | ORDER\
93 | OUTER\
94 | PLAN\
95 | PRAGMA\
96 | PRIMARY\
97 | QUERY\
98 | RAISE\
99 | REFERENCES\
100 | REGEXP\
101 | REINDEX\
102 | RELEASE\
103 | RENAME\
104 | REPLACE\
105 | RESTRICT\
106 | RIGHT\
107 | ROLLBACK\
108 | ROW\
109 | SAVEPOINT\
110 | SELECT\
111 | SET\
112 | TABLE\
113 | TEMP\
114 | TEMPORARY\
115 | THEN\
116 | TO\
117 | TRANSACTION\
118 | TRIGGER\
119 | UNION\
120 | UNIQUE\
121 | UPDATE\
122 | USING\
123 | VACUUM\
124 | VALUES\
125 | VIEW\
126 | VIRTUAL\
127 | WHEN\
128 | WHERE}
--------------------------------------------------------------------------------
/tutorial_files/test.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tthibo/SQL-Tutorial/0efb78bee64373c0f96bfdcbfbae124dd7d1103e/tutorial_files/test.sqlite
--------------------------------------------------------------------------------