Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sql-assessment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ create table campaign_info (

1. Write a query to get the sum of impressions by day.
2. Write a query to get the top three revenue-generating states in order of best to worst. How much revenue did the third best state generate?
3. Write a query that shows total cost, impressions, clicks, and revenue of each campaign. Make sure to include the campaign name in the output.
3. Write a query that shows total cost, impressions, clicks, and revenue of each campaign. Make sure to include the campaign name in the output.
4. Write a query to get the number of conversions of Campaign5 by state. Which state generated the most conversions for this campaign?
5. In your opinion, which campaign was the most efficient, and why?

Expand Down
46 changes: 46 additions & 0 deletions sql-assessment/answers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- 1. Write a query to get the sum of impressions by day.
SELECT date, SUM(impressions) AS total_impressions
FROM marketing_performance
GROUP BY date
ORDER BY date;

--2. Write a query to get the top three revenue-generating states in order of best to worst. How much revenue did the third best state generate?
SELECT state, SUM(revenue) AS total_revenue
FROM website_revenue
GROUP BY state
ORDER BY total_revenue DESC;

--Third best state was Ohio at 37,577 total impressions


--3. Write a query that shows total cost, impressions, clicks, and revenue of each campaign. Make sure to include the campaign name in the output.
SELECT
c.Campaign_name,
SUM(mp.cost) AS total_cost,
SUM(mp.clicks) AS total_clicks,
SUM(mp.conversions) AS total_conversions,
SUM(mp.impressions) AS total_impressions
FROM Campaign_info c
INNER JOIN Marketing_performance mp ON c.ID = mp.campaign_id
GROUP BY c.name;


--4. Write a query to get the number of conversions of Campaign5 by state. Which state generated the most conversions for this campaign?
SELECT mp.geo, Sum(mp.conversions) AS total_conversions
FROM marketing_performance AS mp INNER JOIN Campaign_info AS ci ON mp.campaign_id = ci.ID
WHERE ((([ci].[Campaign_name])='Campaign5'))
GROUP BY mp.geo
ORDER BY Count(total_conversions) DESC , [ci].[Campaign_name];

-- Ohio generated the most conversions for campaign5 at 442


--5. In your opinion, which campaign was the most efficient, and why?

--campaign5 was the most efficient because it had the lowest cost per conversion at $1.91 among all campaigns.

--6. Write a query that showcases the best day of the week (e.g., Sunday, Monday, Tuesday, etc.) to run ads.
SELECT WeekdayName(date) AS day_of_week, AVG(conversions) AS average_conv
FROM Marketing_performance
GROUP BY day_of_week
ORDER BY average_conv DESC;