Introduction to Oracle SQL
Hadrien Lacroix
Content Developer
SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
SELECT BillingCountry, AVG(Total) > 100) AS Average
-> FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
-> WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
-> GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
-> HAVING AVG(Total) > 100
ORDER BY Average DESC
-> SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
SELECT BillingCountry, AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
-> ORDER BY Average DESC
SELECT BillingCountry,
AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
WHERE
, GROUP BY
, and HAVING
ORDER BY
SELECT BillingCountry,
AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100
ORDER BY Average DESC
WHERE
clauseHAVING
clauseSELECT BillingCountry,
AVG(Total) > 100) AS Average
FROM Invoice
WHERE BillingCity <> 'Paris'
GROUP BY BillingCountry
HAVING AVG(Total) > 100)
ORDER BY Average DESC
HAVING
clauseWHERE
clauseFROM
and JOIN
s: determine which data is being queried
WHERE
: filter individual rows
GROUP BY
: group rows
HAVING
: filter groups
SELECT
: select columns and apply functions on columns
DISTINCT
: remove duplicates
UNION
, UNION ALL
, INTERSECT
, MINUS
: apply set operators
ORDER BY
: order rows
Introduction to Oracle SQL