Back to Editor

Solution: 35. Average Views per Video by Channel

Medium

Problem Detail:

Write a SQL query to calculate the average number of views per video for each channel.

Answer SQL Query:

SELECT c.channel_name,
       AVG(s.view_count) AS avg_views_per_video
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
ORDER BY avg_views_per_video DESC;
You can easily copy this solution, switch back to your editor tab, paste it, and run the SQL!