I Learnded SQL And So Can You!

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Microsoft Excel Working with Excel Lists, Subtotals and Pivot Tables.
Introduction The concept of “SQL Injection”
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Set operators Union Minus Intersect match ALL COLUMNS must have same ID, column names.
Assignment 1 Pointers ● Be sure to use all tags properly – Don't use a tag for something it wasn't designed for – Ex. Do not use heading tags... for regular.
Concepts of Database Management, 4th Edition, Pratt & Adamski
Chapter 2 Querying a Database
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Computer Science 101 Web Access to Databases SQL – Extended Form.
State of Connecticut Core-CT Project Query 4 hrs Updated 1/21/2011.
MS Access: Database Concepts Instructor: Vicki Weidler.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Exam Review – Queries & MORE! Access SimNet Exam Access Case Exam Final Exam.
Chapter 9 Database Management Discovering Computers Fundamental.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Chapter 9 Joining Data from Multiple Tables
NOSQL DATABASES Please remember to read the NOSQL Distilled book and the Seven Databases book.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
CS1100: Microsoft Access Managing Data in Relational Databases Created By Martin Schedlbauer CS11001Microsoft Access - Introduction.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
Instructor: Craig Duckett Lecture 03: Tuesday, April 14, 2015 SQL Sorting, Aggregates and Joining Tables 1.
Indexes and Views Unit 7.
LANDESK SOFTWARE CONFIDENTIAL Tips and Tricks with Filters Jenny Lardh.
Computer Science & Engineering 2111 Lecture 13 Outer Joins 1.
Finding a PersonBOS Finding a Person! Building an algorithm to search for existing people in a system Rahn Lieberman Manager Emdeon Corp (Emdeon.com)
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
 Review quiz. Answer questions.  Discuss queries: ◦ What is a query? Turning data stored in a database into information for decision making. ◦ You: Completed.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SQL for Super Users Presented by: Adam Jacobson Red Three Consulting, Inc.
about me – Austin Senseman, CFA 5 years in Financial Services, Managed analytics for sales, marketing, risk, finance, &
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Relational Databases Today we will look at: Different ways of searching a database Creating queries Aggregate Queries More complex queries involving different.
UNDERSTANDING ACADEMIC EXPECTATIONS Linda Williams Learnings Strategies Student Academic Success Services sass.queensu.ca Learning Strategies, Student.
Advanced spreadsheet tips & tricks
AP CSP: Cleaning Data & Creating Summary Tables
More SQL: Complex Queries,
Microsoft Office Access 2010 Lab 3
Presented by: Teererai Marange
SQL IS MY FRIEND Level 1 Example of typical cover slide.
Applied CyberInfrastructure Concepts Fall 2017
Larry Reaves October 9, 2013 Day 16: Access Chapter 2 Larry Reaves October 9, 2013.
Reporting Overview Business Goals Demystify the report menu
Fast Action Links extension A love letter to CiviCRM
ECONOMETRICS ii – spring 2018
SQL Server May Let You Do It, But it Doesn’t Mean You Should
MySQL - Creating donorof database offline
Writing Basic SQL SELECT Statements
Using SQL to Prepare Data for Analysis
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
The Killing Cursors Cyndi Johnson
Research and Its Applications
Database Vs. Data Warehouse
Evaluating Websites The Good, the Bad, and the Misleading!
DAY 1 - Explore - AP Performance Task Prep
Chapter 4 Summary Query.
HAVING,INDEX,COMMIT & ROLLBACK
Writing Basic SQL SELECT Statements
Cyndi Johnson Senior Software Engineer at AdvancedMD Killing Cursors.
M1G Introduction to Database Development
Introducing DAX July 11th, 2015.
Cyndi Johnson Senior Software Engineer at AdvancedMD Killing Cursors.
Using Veera with R and Shiny to Build Complex Visualizations
University Housing & The Hungarian Algorithm
Presentation transcript:

I Learnded SQL And So Can You!

Background Started with iovation as a Client Manager in 2015. After seven months, moved to a Data Analyst role. Before iovation, I had experience with data analysis, but no experience retrieving data. Starting my Data Analyst role at iovation, I had… No prior knowledge of SQL No computer science background Used Excel spreadsheets for data analysis Never heard of Postgres My first task: Get familiar with iovation’s Postgres QA databases

Me after one day…

Me after one day…

Learning SQL Takes Focus ”You must feel the force around you. Here… between you and me... The tree... The rock... The SELECT... The FROM... JOINING ON... everything.” - Yoda, The Empire Stikes Back (1980) Luckily, the SQL syntax is pretty easy to understand 😄😄😄

How familiar are we with SQL? I can build and maintain large scale optimized postgres databases I can write fancy SQL queries that run efficiently I regularly use relation databases and write SQL I’ve used relational databases like Postgres and know enough SQL to get by I’ve written a few SQL queries I’ve heard of SQL

Basic Layout of a SQL Query SELECT – The columns you want to see in the result set FROM – The table you are pulling data from JOIN – Other tables you are pulling data from, specifying how they are related to each other WHERE – Criteria to filter your result set GROUP BY – Summarize/compute results into groups ORDER BY – Sort the data

Reading SQL vs Understanding SQL SELECT FROM JOIN WHERE GROUP BY ORDER BY FROM JOIN SELECT GROUP BY WHERE ORDER BY

CONCEPT – JOINs Basic Concept: JOINs combine rows from two (or more) tables, based on a related column. Each row from the two related column is evaluated to see if the values match. When they match, the rows are combined into a temporary table. Columns are then selected from the temporary table to be shown in the results. Core concept of a relational database Many types of JOINs to account for different ways of relating tables to one-another (can even JOIN a table to itself) The database’s Query Optimizer is in charge of figuring out the most efficient way to join these tables together SELECT p.patient_nbr, at.description, p.age FROM patients p JOIN admission_type at ON p.admission_type_id = at.id

CONCEPT – GROUP BY Clause SELECT p.age, COUNT(p.patient_nbr), FROM patients p JOIN admission_type at ON p.admission_type_id = at.id Basic Concept: Group rows together based on matched values, and compute (summarize, rollup,) values based on the groups. - Aggregation

Consistency … not data consistency (althought thats important too) I’m talking about consistent process and organization for your work!

Consistency also means organized… Whatever workflow process you have, be consistent and organized. Consistent requirements Keeps you and the requestor/reviewer on the same page (sometimes it’s hard to get consistent requirements) Consistent validation steps Reviewers can can understand why you did what you did Consistent workflow See Google Doc

Use Aliases No aliases 👎 Has aliases 👍👍👍 Aliases are your friend! Use them and be consistent when using them. See examples. While this top query works without aliases, its confusing. We can’t tell which fields in the SELECT come from which table. Aliases… Simplify your work: don’t have to write out full table names Allow you to rename fields to something more applicable Help with confusion (there happens to be a ‘description’ field in multiple tables...) If left out, often cause errors due to ambiguitiy Give reviewers a helping hand Has aliases 👍👍👍

Validation Extremely important. Often forgotten. Why? Accuracy - You want to be sure that the result-set is the expected one. Code Reviews - Reviewers might want to know what you did. Data results can be surprising - Be prepared to defend your work! Revisiting a query - If you wrote a query a month ago, you might not remember why you did that weird WHERE clause. Know how to validate your query Simple things I look at… Row-counts match: If the results looks odd, it probably isn’t correct. Are there oddities in the data itself?

Tips, Tricks and Gotchas Comments Think ahead about how much data you’re retrieving SELECT * FROM big_table is bad COUNT(*) - Great for validation and learning about a table SELECT 1; SELECT 2+2; SELECT function(); - Great for date math! COALESCE(); WHERE 1 = 1 WHERE TRUE BEGIN TRANSACTION Gotchas NULLs: are they truly NULL values, or are they empty strings? Joining on different data types

Resources stackoverflow.com W3schools.com discuss.codecademy.com Free Not Free, but can be worth it stackoverflow.com W3schools.com discuss.codecademy.com Free Data Sources NOAA climate datasets: http://ncdc.noaa.gov/data-access/quick-links American Economic Ass. (AEA): http://www.aeaweb.org/RFE/toc.php?show=complete Google Finance: https://www.google.com/finance EHDP Large Health Data Sets: http://www.ehdp.com/vitalnet/datasets.htm Airports and their locations: http://www.infochimps.com/datasets/airports-and- their-locations Machine Learning Data Set Repository: http://mldata.org/ Facebook Social Networks (since 2007): http://law.di.unimi.it/datasets.php Lynda.com Udemy.com Corsera.com