Skip to content

Commit

Permalink
Add SQL reconciliation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnOlutubo authored May 20, 2024
1 parent aa5bb2b commit 7fd5d9a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
47 changes: 47 additions & 0 deletions assets/scripts/youtubers_with_most_subs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
# 1. Define variables
# 2. Create a CTE that rounds the average views per video
# 3. Select the column you need and create calculated columns from existing ones
# 4. Filter results by Youtube channels
# 5. Sort results by net profits (from highest to lowest)
*/


-- 1.
DECLARE @conversionRate FLOAT = 0.02; -- The conversion rate @ 2%
DECLARE @productCost FLOAT = 5.0; -- The product cost @ $5
DECLARE @campaignCost FLOAT = 50000.0; -- The campaign cost @ $50,000


-- 2.
WITH ChannelData AS (
SELECT
channel_name,
total_views,
total_videos,
ROUND((CAST(total_views AS FLOAT) / total_videos), -4) AS rounded_avg_views_per_video
FROM
youtube_db.dbo.view_uk_youtubers_2024
)

-- 3.
SELECT
channel_name,
rounded_avg_views_per_video,
(rounded_avg_views_per_video * @conversionRate) AS potential_units_sold_per_video,
(rounded_avg_views_per_video * @conversionRate * @productCost) AS potential_revenue_per_video,
((rounded_avg_views_per_video * @conversionRate * @productCost) - @campaignCost) AS net_profit
FROM
ChannelData


-- 4.
WHERE
channel_name in ('NoCopyrightSounds', 'DanTDM', 'Dan Rhodes')


-- 5.
ORDER BY
net_profit DESC
47 changes: 47 additions & 0 deletions assets/scripts/youtubers_with_most_videos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
# 1. Define variables
# 2. Create a CTE that rounds the average views per video
# 3. Select the columns you need and create calculated columns from existing ones
# 4. Filter results by YouTube channels
# 5. Sort results by net profits (from highest to lowest)
*/


-- 1.
DECLARE @conversionRate FLOAT = 0.02; -- The conversion rate @ 2%
DECLARE @productCost FLOAT = 5.0; -- The product cost @ $5
DECLARE @campaignCostPerVideo FLOAT = 5000.0; -- The campaign cost per video @ $5,000
DECLARE @numberOfVideos INT = 11; -- The number of videos (11)


-- 2.
WITH ChannelData AS (
SELECT
channel_name,
total_views,
total_videos,
ROUND((CAST(total_views AS FLOAT) / total_videos), -4) AS rounded_avg_views_per_video
FROM
youtube_db.dbo.view_uk_youtubers_2024
)


-- 3.
SELECT
channel_name,
rounded_avg_views_per_video,
(rounded_avg_views_per_video * @conversionRate) AS potential_units_sold_per_video,
(rounded_avg_views_per_video * @conversionRate * @productCost) AS potential_revenue_per_video,
((rounded_avg_views_per_video * @conversionRate * @productCost) - (@campaignCostPerVideo * @numberOfVideos)) AS net_profit
FROM
ChannelData


-- 4.
WHERE
channel_name IN ('GRM Daily', 'Man City', 'YOGSCAST Lewis & Simon ')


-- 5.
ORDER BY
net_profit DESC;
48 changes: 48 additions & 0 deletions assets/scripts/youtubers_with_most_views.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
# 1. Define variables
# 2. Create a CTE that rounds the average views per video
# 3. Select the columns you need and create calculated columns from existing ones
# 4. Filter results by YouTube channels
# 5. Sort results by net profits (from highest to lowest)
*/



-- 1.
DECLARE @conversionRate FLOAT = 0.02; -- The conversion rate @ 2%
DECLARE @productCost MONEY = 5.0; -- The product cost @ $5
DECLARE @campaignCost MONEY = 130000.0; -- The campaign cost @ $130,000



-- 2.
WITH ChannelData AS (
SELECT
channel_name,
total_views,
total_videos,
ROUND(CAST(total_views AS FLOAT) / total_videos, -4) AS avg_views_per_video
FROM
youtube_db.dbo.view_uk_youtubers_2024
)


-- 3.
SELECT
channel_name,
avg_views_per_video,
(avg_views_per_video * @conversionRate) AS potential_units_sold_per_video,
(avg_views_per_video * @conversionRate * @productCost) AS potential_revenue_per_video,
(avg_views_per_video * @conversionRate * @productCost) - @campaignCost AS net_profit
FROM
ChannelData


-- 4.
WHERE
channel_name IN ('Mister Max', 'DanTDM', 'Dan Rhodes')


-- 5.
ORDER BY
net_profit DESC;

0 comments on commit 7fd5d9a

Please sign in to comment.