-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswers.sql
More file actions
40 lines (37 loc) · 1.08 KB
/
answers.sql
File metadata and controls
40 lines (37 loc) · 1.08 KB
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
-- Question 1
-- Show payment date and total amount paid on that date,
-- sorted by payment date descending, showing only the top 5 latest payment dates.
SELECT
paymentDate,
SUM(amount) AS total_payment_amount
FROM payments
GROUP BY paymentDate
ORDER BY paymentDate DESC
LIMIT 5;
-- Question 2
-- Find the average credit limit of each customer,
-- grouped by customer name and country.
SELECT
customerName,
country,
AVG(creditLimit) AS average_credit_limit
FROM customers
GROUP BY customerName, country;
-- Question 3
-- Find the total price of products ordered,
-- calculated as quantity ordered multiplied by price each,
-- grouped by product code and quantity ordered.
SELECT
productCode,
quantityOrdered,
SUM(quantityOrdered * priceEach) AS total_price
FROM orderdetails
GROUP BY productCode, quantityOrdered;
-- Question 4
-- Find the highest payment amount for each check number,
-- grouped by check number.
SELECT
checkNumber,
MAX(amount) AS highest_payment_amount
FROM payments
GROUP BY checkNumber;