-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateTableLeaderboard.sql
More file actions
44 lines (37 loc) · 1.08 KB
/
Copy pathcreateTableLeaderboard.sql
File metadata and controls
44 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- Clean and transform the leaderboard dataset
-- Richard Kelson
-- June 2021
USE AOE2
DROP TABLE IF EXISTS #leaderboard
-- Unpack the JSON file
Declare @JSON varchar(max)
SELECT @JSON = BulkColumn
FROM OPENROWSET (BULK 'C:\Users\richa\OneDrive\Documents\Career\Portfolio\AOE2\API Data\leaderboard.JSON', SINGLE_CLOB) as j
SELECT *
INTO #leaderboard
FROM OPENJSON (@JSON)
WITH(profile_id varchar(128),
rank int,
rating smallint,
steam_id varchar(128),
name varchar(256),
clan varchar(256),
country varchar(128),
previous_rating smallint,
highest_rating smallint,
streak smallint,
lowest_streak smallint,
highest_streak smallint,
games smallint,
wins smallint,
losses smallint,
drops smallint,
last_match int,
last_match_time int
)
-- where steam IDs are the same, want to concatenate together
-- (some players have multiple accounts - assume one user has
-- consistent steam_id)
-- update: just remove extras for now
SELECT * INTO leaderboard FROM #leaderboard
WHERE steam_id IN (SELECT DISTINCT steam_id FROM #leaderboard)