SQL (pronounced “ess-que-el”) stands for Structured Query Language.
It is the standard language for relational database management systems.
Used by: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, PostgreSQL, MySQL, etc.
The standard SQL commands such as “Select”, “Insert”, “Update”, “Delete”, “Create”, and “Drop” can accomplish almost everything that one needs to do with a database.
select origin
,dest
,carrier
,flight
from flights
limit5
5 records
origin
dest
carrier
flight
EWR
IAH
UA
1545
LGA
IAH
UA
1714
JFK
MIA
AA
1141
JFK
BQN
B6
725
LGA
ATL
DL
461
Conditional Select
selectyear || '-' || month || '-' || dayasdate
,origin
,dest
,carrier
,flight
from flights
where dest = "MIA"limit5
5 records
date
origin
dest
carrier
flight
2013-1-1
JFK
MIA
AA
1141
2013-1-1
EWR
MIA
AA
1895
2013-1-1
EWR
MIA
UA
1077
2013-1-1
LGA
MIA
AA
1837
2013-1-1
LGA
MIA
DL
2003
Ordered Select
selectyear || '-' || month || '-' || dayasdate
,origin
,dest
,carrier
,flight
from flights
where dest = "MIA"orderbyyeardesc
,monthdesc
,daydesclimit5
5 records
date
origin
dest
carrier
flight
2013-9-9
JFK
MIA
AA
2243
2013-9-9
LGA
MIA
AA
1175
2013-9-9
EWR
MIA
AA
1205
2013-9-9
LGA
MIA
DL
2003
2013-9-9
JFK
MIA
AA
1345
Aggregate Select
select carrier
,count(*) as num_flights
from flights
groupby carrier
orderby num_flights desclimit5
5 records
carrier
num_flights
UA
58665
B6
54635
EV
54173
DL
48110
AA
32729
Combinations (Joins)
select name
,count(*) as num_flights
from flights
leftjoin airlines
on airlines.carrier = flights.carrier
groupby flights.carrier
orderby num_flights desclimit5
5 records
name
num_flights
United Air Lines Inc.
58665
JetBlue Airways
54635
ExpressJet Airlines Inc.
54173
Delta Air Lines Inc.
48110
American Airlines Inc.
32729
A Little More About Joins
Rain and Arrival Delays
select wp.precip_cat
,avg(arr_delay) as avg_arr_delay
from flights
leftjoin (
selectyear
,month
,day
,casewhen precip = 0then'0'when precip > 0and precip <= .0045then'<= .0045'when precip > .0045and precip <= 1then'.0045 - 1'when precip > 1then'>1'endas precip_cat
from weather
) wp
on wp.year = flights.year
and wp.month = flights.month
and wp.day = flights.day
groupby wp.precip_cat
orderby avg_arr_delay desc