Skip to content

Commit 8d17f5f

Browse files
committed
2 parents aabf4e2 + b3d8e14 commit 8d17f5f

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

projects/analyze-twitch-data-with-sqlite/analyze-twitch-data-with-sqlite.mdx

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ In the terminal, type:
141141
sqlite twitch.db
142142
```
143143

144-
Inside the SQLite prompt, create a table called `streamers`:
144+
Inside the SQLite prompt, create a table called `streamers2021`:
145145

146146
```sql
147-
CREATE TABLE streamers (
147+
CREATE TABLE streamers2021 (
148148
channel TEXT PRIMARY KEY,
149149
watch_time INTEGER,
150150
stream_time INTEGER,
@@ -181,14 +181,14 @@ Make sure your CSV file is in the same folder. Then in the SQLite prompt:
181181

182182
```terminal
183183
.mode csv
184-
.import streamers2021.csv streamers
184+
.import streamers2021.csv streamers2021
185185
```
186186

187187
To make sure it’s working:
188188

189189
```
190190
SELECT *
191-
FROM streamers
191+
FROM streamers2021
192192
LIMIT 10;
193193
```
194194

@@ -238,15 +238,42 @@ The output should look something like this:
238238

239239
[screenshot image]
240240

241-
Let’s find all the unique games in this dataset using the `DISTINCT` keyword:
241+
### Languages
242+
243+
Let’s find all the unique languages in this dataset using the `DISTINCT` keyword:
242244

243245
```
244-
SELECT DISTINCT column_name
245-
FROM table_name;
246+
SELECT DISTINCT language
247+
FROM streamers;
246248
```
247249

248250
The results should look like:
249251

252+
- English
253+
- Portuguese
254+
- Spanish
255+
- German
256+
- Korean
257+
- French
258+
- Russian
259+
- Japanese
260+
- Chinese
261+
- Czech
262+
- Turkish
263+
- Italian
264+
- Polish
265+
- Thai
266+
- Arabic
267+
- Slovak
268+
- Other
269+
- Hungarian
270+
- Greek
271+
- Finnish
272+
- Swedish
273+
274+
275+
For `streamers2024` table, you can do distinct games:
276+
250277
- League of Legends
251278
- DayZ
252279
- Dota 2
@@ -256,18 +283,45 @@ The results should look like:
256283
- The Binding of Isaac: Rebirth
257284
- etc.
258285

286+
###
287+
288+
259289
## Using Aggregate Functions
260290

261291
Now it’s a good time to write down the questions that we have.
262292

263293
Here are some of mine:
264294

295+
- _Who were the hottest rising streamers in 2021?_
265296
- _What are the most popular games in the stream table?_
266297
- _These are some big numbers from the game League of Legends (also known as LoL). Where are these LoL stream viewers located?_
267298
- _The player column contains the source the user is using to view the stream (site, iPhone, Android, etc). Create a list of players and their number of streamers._
268299

269300
Let’s go through each of these one by one.
270301

302+
### Who are the hottest rising streamers in 2021?
303+
304+
Aka who gained the most followers?
305+
306+
For this, we can use the `MAX()` function:
307+
308+
```sql
309+
SELECT channel, MAX(followers_gained)
310+
FROM streamers
311+
ORDER BY followers_gained
312+
LIMIT 5;
313+
```
314+
315+
The results are:
316+
317+
```output
318+
auronplay,3966525
319+
Rubius,3820532
320+
TheGrefg,3593081
321+
Bugha,2220765s
322+
pokimane,2085831
323+
```
324+
271325
### Top 10 Most Popular Games
272326

273327
To find out this one, we need to use `COUNT()` and `GROUP BY`:

0 commit comments

Comments
 (0)