You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: projects/analyze-twitch-data-with-sqlite/analyze-twitch-data-with-sqlite.mdx
+61-7Lines changed: 61 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,10 +141,10 @@ In the terminal, type:
141
141
sqlite twitch.db
142
142
```
143
143
144
-
Inside the SQLite prompt, create a table called `streamers`:
144
+
Inside the SQLite prompt, create a table called `streamers2021`:
145
145
146
146
```sql
147
-
CREATETABLEstreamers (
147
+
CREATETABLEstreamers2021 (
148
148
channel TEXTPRIMARY KEY,
149
149
watch_time INTEGER,
150
150
stream_time INTEGER,
@@ -181,14 +181,14 @@ Make sure your CSV file is in the same folder. Then in the SQLite prompt:
181
181
182
182
```terminal
183
183
.mode csv
184
-
.import streamers2021.csv streamers
184
+
.import streamers2021.csv streamers2021
185
185
```
186
186
187
187
To make sure it’s working:
188
188
189
189
```
190
190
SELECT *
191
-
FROM streamers
191
+
FROM streamers2021
192
192
LIMIT 10;
193
193
```
194
194
@@ -238,15 +238,42 @@ The output should look something like this:
238
238
239
239
[screenshot image]
240
240
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:
242
244
243
245
```
244
-
SELECT DISTINCT column_name
245
-
FROM table_name;
246
+
SELECT DISTINCT language
247
+
FROM streamers;
246
248
```
247
249
248
250
The results should look like:
249
251
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
+
250
277
- League of Legends
251
278
- DayZ
252
279
- Dota 2
@@ -256,18 +283,45 @@ The results should look like:
256
283
- The Binding of Isaac: Rebirth
257
284
- etc.
258
285
286
+
###
287
+
288
+
259
289
## Using Aggregate Functions
260
290
261
291
Now it’s a good time to write down the questions that we have.
262
292
263
293
Here are some of mine:
264
294
295
+
-_Who were the hottest rising streamers in 2021?_
265
296
-_What are the most popular games in the stream table?_
266
297
-_These are some big numbers from the game League of Legends (also known as LoL). Where are these LoL stream viewers located?_
267
298
-_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._
268
299
269
300
Let’s go through each of these one by one.
270
301
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
+
LIMIT5;
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
+
271
325
### Top 10 Most Popular Games
272
326
273
327
To find out this one, we need to use `COUNT()` and `GROUP BY`:
0 commit comments