Skip to content

Commit 51c67fc

Browse files
authored
Refactor SQL queries for price calculation
Updated SQL queries to include price calculation and rounding.
1 parent a313ab9 commit 51c67fc

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

02_activities/assignments/Cohort_8/assignment1.sql

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,14 @@ filtered by customer IDs between 8 and 10 (inclusive) using either:
3434
*/
3535
-- option 1
3636
# logic of price is added line 41
37-
SELECT
38-
customer_id,
39-
cp.product_id,
40-
(quantity * cost_to_customer_per_qty),
41-
product_name
42-
FROM customer_purchases as cp
43-
INNER JOIN product as p
44-
ON cp.product_id = p.product_id
45-
WHERE customer_id >= 8 AND customer_id <= 10
46-
ORDER BY customer_id
37+
SELECT *, ROUND((quantity * cost_to_customer_per_qty), 2) AS price
38+
FROM customer_purchases
39+
WHERE customer_id >= 8 AND customer_id <= 10;
4740

4841
-- option 2
49-
# used range as between
50-
SELECT
51-
customer_id,
52-
cp.product_id,
53-
(quantity * cost_to_customer_per_qty),
54-
product_name
55-
FROM customer_purchases as cp
56-
INNER JOIN product as p
57-
ON cp.product_id = p.product_id
58-
WHERE customer_id BETWEEN 8 AND 10
59-
ORDER BY customer_id
42+
SELECT *, ROUND((quantity * cost_to_customer_per_qty), 2) AS price
43+
FROM customer_purchases
44+
WHERE customer_id BETWEEN 8 AND 10;
6045

6146

6247
--CASE

0 commit comments

Comments
 (0)