Appunti SQL Structured Query Language, Study notes of Computer Science

Structured Query Language è un linguaggio standardizzato per database basati sul modello relazionale (RDBMS), progettato per le

Typology: Study notes

2018/2019

Uploaded on 12/17/2019

FlaviaBorg
FlaviaBorg 🇬🇧

4.5

(2)

3 documents

1 / 70

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fundamentals of Databases and SQL
https://analyticsga-euwest1.generalassemb.ly/browser/
bit.ly/databasesql
analyticsga
SQL vs Excel
SQL: Structured Quary Language
Larger data sets / unlimited data!
Quicker !
More Complex data !
Live data !
Secure!
Cloud: lots of servers together !
ie. !
MySQL opensource!
T-SQL microsoft!
PostgreSQL opensource!
- SQL one language but there are subtle dierences for ex. English: British, American,
Canadian!
Excel
Data loss !
EXCEL VS SQL
Computer <-> Server !
Spreadsheet <-> Database!
Tab/sheet <-> Table !
Column <-> Variable !
Formulas <-> Script !
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46

Partial preview of the text

Download Appunti SQL Structured Query Language and more Study notes Computer Science in PDF only on Docsity!

Fundamentals of Databases and SQL https://analyticsga-euwest1.generalassemb.ly/browser/ bit.ly/databasesql [email protected] analyticsga SQL vs Excel SQL: Structured Quary Language Larger data sets / unlimited data Quicker More Complex data Live data Secure Cloud: lots of servers together ie. MySQL opensource T-SQL microsoft PostgreSQL opensource

  • SQL one language but there are subtle differences for ex. English: British, American, Canadian Excel Data loss EXCEL VS SQL Computer <-> Server Spreadsheet <-> Database Tab/sheet <-> Table Column <-> Variable Formulas <-> Script

Bare minimum: ESSENTIAL [ SELECT (what do you want to see) FROM (where to get the data from?)

table * (show me everything)

ORDER BY ( How to sort data?) Columns ASC (ASCENDING) /DESC (DESCENDING) LIMIT (how many rows to show?) number

Specify which columns you want to see:

Select category_name, item_description

CASE INSENSITIVE: ILIKE

%: WILDCARD PARTIAL MATCH

NOT LIKE:

MORE FLEXIBLE:

**3) Which tequilas or scotch whiskies have a case cost of more than 100$?

  1. Which whiskies of any kind cost between $100 and $150?**

5) Which products except tequilas cost less than 100$ or more than 200$? REMINDER:

  1. ALWAYS 3 components for a condition: column, test, value
  2. Think about casing
  3. Is it a partial match? -> add %
  4. != not ILIKE
  5. In with Like

Filtering and Aggregating in SQL: CAST AND DISTINCT Text:

  • letters - numbers 123 - symbols ie.

Getting rid of duplicates and achieving unique values: DISTINCT

The CEO OF IOWA LIQUOR STORES Ltd has a question for you to research: From The Iowa Liquor Datas I only want information about vendor 305. Can you get me the bottle price and proof for each distinct product? The bottle price should be less than 5 or the proof is greater than 100, either is fine Mistakes: proof > 100 : text > integer so (CAST (proof as integer) bottle_price < 5: money < integer so Cast (bottle_pice as numeric) < 5 vendor = 305

Introduction: AGGREGATIONS min, max, average, sum, count SELECT (what do you want to see)

FROM (where to get the data from?) table * (show me everything)

WHERE (How to filter rows) column test value condition AND/OR column, test ( =, !=,

,<, IN (…, …., ) , LIKE (case sensitive), ILIKE (case insensitive) GROUP BY (how to aggregate the data?) ORDER BY (How to sort data?) columns ASC/DESC LIMIT (how many rows to show?) number

SELECT categorical variables, (continuous variables) Apply aggregate function FROM GROUP BY categorical variables Aggregations Exercise: 1 ) What was the total revenue an total quantity sold? Hint: for revenue use column total and for quantity use column bottle qty

3) Which was the county with most transactions? MOST = Count

5) Show the last time that each store made a transaction

6) Which were the 3 top selling counties in terms of revenue