Twitch is the world’s leading video platform and community for gamers, with more than 15+ million unique daily visitors. In this project, you will be working with two fictional tables that contain Twitch's streaming data and chat room data and answering questions about them:
- Streaming data is in the
streamtable - Chat usage data is in the
chattable
Each question can be answered using one (or more) SQL queries. The answer to the first question is given. The rest is for you to figure out. Let's get started!
SELECTall columns from the first 20 rows ofstreamtable.
SELECT *
FROM stream
LIMIT 20;SELECTall columns from the first 20 rows ofchattable.
SELECT *
FROM chat
LIMIT 20;- There is something wrong with the
chattable. Its 1st row is actually the column names. Delete the first row of thechattable.
DELETE FROM chat
WHERE time = 'time';- What are the
DISTINCTgamein thestreamtable?
SELECT DISTINCT game
FROM stream;- What are the
DISTINCTchannels in thestreamtable?
SELECT DISTINCT channel
FROM stream;- What are the most popular games in
stream? Create a list of games and their number of viewers.ORDER BYfrom most popular to least popular.
SELECT game, COUNT (login)
FROM stream
GROUP BY game
ORDER BY count(login) DESC;-
There are some big numbers from the game
League of Legendsinstream. Where are theseLeague of Legend playerslocated?- Hint: Create a list.
SELECT DISTINCT country FROM stream
WHERE game = 'League of Legends';- The
playercolumn shows the source/device the viewer is using (site, iphone, android, etc). Create a list of players and their number of streamers.
SELECT player, COUNT (login)
FROM stream
GROUP BY player
ORDER BY count(login) DESC;-
Using a
CASEstatement, create a new column namedgenrefor each of the games instream. Group the games into their genres: Multiplayer Online Battle Arena (MOBA), First Person Shooter (FPS), and Others. Your logic should be: If it isLeague of LeaguesorDota 2orHeroes of the Storm→ then it isMOBA. If it isCounter-Strike: Global Offensive→ then it isFPS. Else, it isOthers.- Hint: Use
GROUP BYandORDER BYto showcase only the unique game titles.
- Hint: Use
SELECT *,
CASE
WHEN game = 'League of Legends' OR game = 'Dota 2' OR game = 'Heroes of the Storm' THEN 'MOBA'
WHEN game = 'Counter-Strike: Global Offensive' THEN 'FPS'
ELSE 'Others'
END as 'genre'
FROM stream
-- Remove the next two lines to return to the full table.
GROUP BY game
ORDER BY genre;- The
streamtable and thechattable share a column:device_id. Do aJOINof the two tables on that column.
SELECT *
FROM stream
JOIN chat
ON stream.device_id = chat.device_id;Bonus: Now try to find some other interesting insights from these two tables using SQL!
-- Shows the breakdown of people watching based on the hour
SELECT SUBSTR(time, 12, 2) AS 'hour', COUNT(Login)
FROM stream
GROUP BY hour;-- This breaks down each channel by the number of viewers per game, changing to chat can show the variance between chat views and stream views
SELECT channel, game, COUNT (login)
FROM stream
GROUP BY channel, game
ORDER BY channel, count(login) DESC;