-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathQuiz 2.sql
108 lines (74 loc) · 2.41 KB
/
Quiz 2.sql
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--Q1) Find all the tracks that have a length of 5,000,000 milliseconds or more.
SELECT
COUNT(TrackId)
FROM TRACKS
WHERE Milliseconds >= 5000000;
------------------------------------------------------------------------------------
--Q2) Find all the invoices whose total is between $5 and $15 dollars.
SELECT
InvoiceID,
Total
FROM Invoices
WHERE Total BETWEEN 5 AND 15;
------------------------------------------------------------------------------------
--Q3) Find all the customers from the following States: RJ, DF, AB, BC, CA, WA, NY.
SELECT
FirstName,
LastName,
Company,
State
FROM Customers
WHERE State IN ('RJ','DF','AB','BC','CA','WA','NY');
------------------------------------------------------------------------------------
--Q4) Find all the invoices for customer 56 and 58 where the total was between
-- $1.00 and $5.00.
SELECT
InvoiceId,
InvoiceDate,
CustomerId,
Total
FROM Invoices
WHERE (Total BETWEEN 1 AND 5) AND
CustomerId IN (56,58);
------------------------------------------------------------------------------------
--Q5) Find all the tracks whose name starts with 'All'.
SELECT
TrackId,
Name
FROM Tracks
WHERE Name LIKE 'All%';
------------------------------------------------------------------------------------
--Q6) Find all the customer emails that start with "J" and are from gmail.com.
SELECT
CustomerId,
Email
FROM Customers
WHERE Email LIKE "J%@gmail.com";
------------------------------------------------------------------------------------
--Q7) Find all the invoices from Brasilia, Edmonton, and Vancouver and sort in
-- descending order by invoice ID.
SELECT
InvoiceId,
BillingCity,
Total
FROM Invoices
WHERE BillingCity IN ('Brasilia','Edmonton','Vancouver')
ORDER BY InvoiceId DESC;
------------------------------------------------------------------------------------
--Q8) Show the number of orders placed by each customer and sort the result by
-- the number of orders in descending order.
SELECT
CustomerId,
COUNT(*) AS NumOfOrders
FROM Invoices
GROUP BY CustomerId
ORDER BY NumOfOrders DESC;
------------------------------------------------------------------------------------
--Q9) Find the albums with 12 or more tracks.
SELECT
AlbumId,
Count(*) AS NumOfTracks
FROM Tracks
GROUP BY AlbumId
HAVING COUNT (*) >= 12
ORDER BY NumOfTracks DESC;