File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 1
- # Date created and Last ran : 10-20 -2023
1
+ # Date created and Last ran : 12-1 -2023
2
2
# Queries to solve Steel Data Challenge
3
3
# Challenge 6 - Marketing Analysis
4
4
@@ -196,21 +196,24 @@ HAVING
196
196
total_quantity_sold > (SELECT AVG (quantity) FROM transactions2)
197
197
ORDER BY total_quantity_sold DESC ;
198
198
199
- -- 6. What is the average revenue generated per day during the marketing campaigns?
199
+ /* 6. What is the average revenue generated per day during the marketing campaigns?
200
+ Think before you do this one , we need to calculate the total revenue during eac campaign and then divide it by the number of days in each campaign.*/
201
+
200
202
SELECT
201
203
mc .campaign_name ,
202
- ROUND(AVG (t .quantity * sc .price ), 2 ) as average_daily_revenue
204
+ ROUND(SUM (t .quantity * sc .price ) / DATEDIFF( mc . end_date , mc . start_date ), 2 ) as average_daily_revenue
203
205
FROM
204
206
marketing_campaigns mc
205
207
JOIN
206
208
transactions2 t ON mc .product_id = t .product_id
207
209
JOIN
208
210
sustainable_clothing sc ON mc .product_id = sc .product_id
209
211
GROUP BY
210
- mc .campaign_name
212
+ mc .campaign_name , mc . start_date , mc . end_date
211
213
ORDER BY
212
214
mc .campaign_name ;
213
215
216
+
214
217
-- 7. What is the percentage contribution of each product to the total revenue?
215
218
WITH product_revenue AS (
216
219
SELECT
You can’t perform that action at this time.
0 commit comments