TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2662 1.91K
๐Ÿš€ SQL Project Series #33

YouTube Channel Analytics ๐Ÿ“บ

Analyze videos, creators, views, watch time, engagement, and subscriber growth using SQL to understand content performance and audience behavior.

๐ŸŽฏ Business Objectives

โœ… Analyze video performance
โœ… Track subscriber growth
โœ… Measure audience engagement
โœ… Identify top-performing content
โœ… Compare video categories
โœ… Analyze watch time
โœ… Identify high-performing creators
โœ… Discover the best publishing times

๐Ÿ“‚ Step 1: Create Database

CREATE DATABASE youtube_analytics_db;
USE youtube_analytics_db;


๐Ÿ“‚ Step 2: Create Channels Table

CREATE TABLE channels (
channel_id INT PRIMARY KEY,
channel_name VARCHAR(100),
category VARCHAR(50),
country VARCHAR(50),
created_date DATE
);


๐Ÿ“‚ Step 3: Create Videos Table

CREATE TABLE videos (
video_id INT PRIMARY KEY,
channel_id INT,
video_title VARCHAR(200),
category VARCHAR(50),
publish_date DATETIME,
duration_minutes DECIMAL(6,2),
views BIGINT,
likes INT,
comments INT,
shares INT,
FOREIGN KEY (channel_id)
REFERENCES channels(channel_id)
);


๐Ÿ“‚ Step 4: Create Subscribers Table

CREATE TABLE subscribers (
subscriber_id INT PRIMARY KEY,
channel_id INT,
subscribe_date DATE,
unsubscribe_date DATE,
FOREIGN KEY (channel_id)
REFERENCES channels(channel_id)
);


๐Ÿ“‚ Step 5: Insert Sample Channels

INSERT INTO channels VALUES
(1,'Data Simplifier','Education','India','2023-01-10'),
(2,'Tech World','Technology','India','2022-08-15'),
(3,'Finance Explained','Finance','USA','2021-05-20'),
(4,'Travel Diaries','Travel','India','2023-04-12');


๐Ÿ“‚ Step 6: Insert Sample Videos

INSERT INTO videos VALUES
(101,1,'SQL Interview Questions','Education','2025-01-05 10:00:00',12,15000,900,120,80),
(102,1,'Power BI Dashboard Tutorial','Education','2025-01-08 18:00:00',18,22000,1400,180,150),
(103,2,'Best AI Tools','Technology','2025-01-10 12:00:00',10,35000,2800,310,420),
(104,3,'How to Invest','Finance','2025-01-12 09:00:00',15,28000,2100,250,300),
(105,4,'Top Places in India','Travel','2025-01-15 20:00:00',14,19000,1300,170,200);


๐Ÿ“‚ Step 7: Insert Sample Subscribers

INSERT INTO subscribers VALUES
(1001,1,'2025-01-01',NULL),
(1002,1,'2025-01-03',NULL),
(1003,1,'2025-01-05','2025-03-01'),
(1004,2,'2025-01-02',NULL),
(1005,3,'2025-01-04',NULL),
(1006,4,'2025-01-10',NULL);


๐Ÿง  SQL Concepts You'll Practice

โœ” Joins
โœ” GROUP BY
โœ” HAVING
โœ” CASE WHEN
โœ” CTEs
โœ” Subqueries
โœ” Window Functions
โœ” Ranking
โœ” Date & Time Functions
โœ” Conditional Aggregation

๐Ÿ“Š Business KPIs You Can Build

๐Ÿ“ˆ Total Channels
๐Ÿ“ˆ Total Videos
๐Ÿ“ˆ Total Views
๐Ÿ“ˆ Total Likes
๐Ÿ“ˆ Total Comments
๐Ÿ“ˆ Total Shares
๐Ÿ“ˆ Total Subscribers
๐Ÿ“ˆ Subscriber Growth Rate
๐Ÿ“ˆ Subscriber Churn Rate
๐Ÿ“ˆ Average Views per Video
๐Ÿ“ˆ Average Likes per Video
๐Ÿ“ˆ Average Comments per Video
๐Ÿ“ˆ Engagement Rate
๐Ÿ“ˆ Like-to-View Ratio
๐Ÿ“ˆ Comment-to-View Ratio
๐Ÿ“ˆ Share-to-View Ratio
๐Ÿ“ˆ Watch Time
๐Ÿ“ˆ Average Video Duration
๐Ÿ“ˆ Top 10 Videos by Views
๐Ÿ“ˆ Top Videos by Engagement
๐Ÿ“ˆ Top Performing Categories
๐Ÿ“ˆ Channel-wise Performance
๐Ÿ“ˆ Views by Publishing Day
๐Ÿ“ˆ Views by Publishing Hour
๐Ÿ“ˆ Monthly Views Growth
๐Ÿ“ˆ Subscriber Growth by Month
๐Ÿ“ˆ Content Performance Dashboard

๐Ÿ’ก Example 1: Find Top 5 Videos by Views

SELECT
video_title,
views
FROM videos
ORDER BY views DESC
LIMIT 5;


๐Ÿ’ก Example 2: Calculate Engagement Rate

SELECT
video_title,
views,
likes,
comments,
shares,
ROUND(
100.0 * (likes + comments + shares) / NULLIF(views, 0),
2
) AS engagement_rate
FROM videos
ORDER BY engagement_rate DESC;


๐Ÿ’ก Example 3: Find Top Video in Each Category
  • โค 5
More from @sqlanalyst
  1. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  2. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  3. Oct 7, 2026SQL Interview Series โ€” Part 4 ๐Ÿ“Œ Question 4: Find the Highest Salary in Each Department Suโ€ฆ
  4. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  5. Sep 29, 2026SQL Interview Series โ€” Part 2 ๐Ÿ“Œ Question 2: Find Duplicate Records Suppose you have an Emโ€ฆ
  6. Sep 29, 2026๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ๐˜€ ๐—ง๐—ผ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐—”๐—œ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ๐Ÿš€ โ€‹ Explore 6 free resourceโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’