This repository contains SQL practice questions covering basic queries, aggregations, joins, window functions, and advanced analytics using a video analytics dataset.
I put the dataset code in this file Youtube Analytics Dataset which you can copy paste in DB fiddle (https://www.db-fiddle.com/) and work on these challenges . You can intially test the data set by using the following queries
SELECT * FROM Youtube.creators LIMIT 2;
SELECT * FROM Youtube.videos LIMIT 2;
SELECT * FROM Youtube.daily_views LIMIT 2;
SELECT * FROM Youtube.comments LIMIT 2;
SELECT * FROM Youtube.likes_dislikes LIMIT 2;
SELECT * FROM Youtube.revenue LIMIT 2This dataset is designed to practice:
- SQL Joins
- Aggregations
- Window Functions
- Real-world analytics scenarios
- Data quality checks
- List all videos and their creator names.
- Count total videos per creator.
- Get total comments for a given video.
- List videos published in the last 18 months.
- Find videos longer than 20 minutes.
- Show top 10 videos by total views (aggregate daily_views).
- Show unique categories.
- Count creators per country.
- Get average views per video per creator.
- Find videos with zero comments.
- Total impressions and clicks per video.
- Compute CTR = clicks / impressions per day.
- Average watch time per view (watch_time_seconds / views).
- Daily views trend for a single video.
- Views per category.
- Top 5 videos by watch_time_seconds.
- Average likes/dislikes per video.
- List videos with more dislikes than likes.
- Videos where avg_view_duration < 20% of duration.
- Videos that gained more than 1k views in a day (spikes).
- For each creator, total revenue (ad + subscription + other).
- For each video, last 7-day rolling average views.
- Top performing video per creator by revenue.
- Video comment sentiment breakdown (positive / neutral / negative).
- Videos with impressions but 0 clicks (possible data issue).
- List videos and their peak daily views date.
- Show creators who published more than 10 videos.
- Videos with multiple high-spike days.
- Find videos with payments revenue but zero views (data mismatch).
- Creator-wise average CTR.
- Rank videos by total views within each category (RANK / DENSE_RANK).
- Running total of views per video (window function).
- Monthly growth rate of views for each video (LAG).
- Top 3 videos per month (partition + ranking).
- Percentile of views for each video (NTILE).
- Lead/Lag to calculate day-over-day % change.
- Cumulative watch time per creator.
- Rank creators by average watch time per video.
- Use ROW_NUMBER to deduplicate and get latest daily stats.
- Compute engagement score = (likes + comments + clicks) / impressions.
- Detect anomaly days using z-score on daily views.
- Creator retention: % of videos still getting views after 90 days.
- Find videos causing highest drop-off (low avg_view_duration vs duration).
- Creator lifetime value = total revenue / number of videos.
- Segment videos by length and analyze CTR per segment.
- Identify top comment contributors.
- Videos with >20k impressions but no revenue.
- Monthly revenue pivot by category.
- Funnel analysis: impressions → clicks → views → watch_time.
- Detect inconsistent data across daily metrics tables.