Back to Editor

Solution: 33. Compare Channel Views vs Summed Video Views

Medium

Problem Detail:

Write a SQL query to compare the view_count in channels with the sum of view_count from video_stats for each channel.

Answer SQL Query:

SELECT c.channel_name,
       c.view_count AS channel_view_count,
       SUM(s.view_count) AS summed_video_views
FROM channels c
JOIN videos v
  ON c.channel_id = v.channel_id
JOIN video_stats s
  ON v.video_id = s.video_id
GROUP BY c.channel_id, c.channel_name, c.view_count
ORDER BY summed_video_views DESC;
You can easily copy this solution, switch back to your editor tab, paste it, and run the SQL!