-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart 01.sql
More file actions
33 lines (28 loc) · 765 Bytes
/
Copy pathPart 01.sql
File metadata and controls
33 lines (28 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Basic Query
SELECT *
FROM Customers
WHERE City = 'São Paulo';
-- Sort query
SELECT *
FROM Customers
WHERE City = 'São Paulo';
ORDER BY City, CustomerName # First by city then by customer name;
-- Agregate infos by count - How many albuns per style?
SELECT style, COUNT(Name)
FROM bands
GROUP BY style
-- Agregate infos by avarege - What is the album avarage for each style?
SELECT style, AVG(Albuns)
FROM bands
GROUP BY style
-- Agregate by avarage and condition - Which estilos have albuns avarage above 10?
SELECT style, AVG(Albuns)
FROM bands
GROUP BY style
HAVING AVG(Albuns) > 10
-- What styles have more than one bands formed before 1970?
SELECT style, COUNT(Name)
FROM bands
WHERE Year_Formation < 1970
GROUP BY style
HAVING COUNT(Name) > 1