Skip to content

Commit e28d372

Browse files
authored
Update #6 Marketing Campaign Analysis.sql
1 parent 889834a commit e28d372

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

RAW SQL/#6 Marketing Campaign Analysis.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Date created and Last ran : 10-20-2023
1+
# Date created and Last ran : 12-1-2023
22
# Queries to solve Steel Data Challenge
33
# Challenge 6 - Marketing Analysis
44

@@ -196,21 +196,24 @@ HAVING
196196
total_quantity_sold > (SELECT AVG(quantity) FROM transactions2)
197197
ORDER BY total_quantity_sold DESC;
198198

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+
200202
SELECT
201203
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
203205
FROM
204206
marketing_campaigns mc
205207
JOIN
206208
transactions2 t ON mc.product_id = t.product_id
207209
JOIN
208210
sustainable_clothing sc ON mc.product_id = sc.product_id
209211
GROUP BY
210-
mc.campaign_name
212+
mc.campaign_name, mc.start_date, mc.end_date
211213
ORDER BY
212214
mc.campaign_name;
213215

216+
214217
-- 7. What is the percentage contribution of each product to the total revenue?
215218
WITH product_revenue AS (
216219
SELECT

0 commit comments

Comments
 (0)