CS/INFO 4154: Analytics-driven Game Design Class 20: SQL
Final Course Deadlines We will not meet during the scheduled exam time Final report will be due at the end of exam time Cornell cannot delete exam from Student Center Final (Kongregate) Report due: Saturday, December 9th, NOON Final Peer Evaluations due: Monday, December 11th, 11:59pm
Mon Wed Fri 10/11 MySQL 10/13 Beta Playtesting 1 10/16 Beta Playtesting 2 10/18 Beta Postmortems 10/19: Midterm Peer Evaluations Due
Beta Postmortems Similar to Alpha postmortems Report something learned from analytics perfectly fine if not very insightful e.g. players clicked 5436 times!
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
SQL Structured Query Language a programming language designed to manage data stored in relational databases
SHOW TABLES Shows tables within current database mysql> SHOW TABLES; +----------------------------+ player_action_log player_pageload_log player_quest_log users +----------------------------+ 4 rows in set (0.00 sec)
Sample table: actions player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8)
DESCRIBE Tells you the table schema Example: DESCRIBE actions; important +-----------+--------------+------+-----+---------+-------+ Field Type Null Key Default Extra +-----------+--------------+------+-----+---------+-------+ player_id int(11) YES NULL quest_id int(11) YES NULL level_id int(11) YES NULL time int(11) YES NULL detail varchar(255) YES NULL +-----------+--------------+------+-----+---------+-------+
SELECT The basic query SELECT <attributes> FROM <one or more tables>;
SELECT player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) SELECT player_id FROM actions; player_id 0 0 0 0 1 1
DISTINCT Filters results for unique values Can be used as a keyword: SELECT DISTINCT player_id FROM actions; Can also be used as a function: SELECT DISTINCT(player_id) FROM actions;
DISTINCT player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) SELECT DISTINCTplayer_id FROM actions; player_id 0 1
COUNT() Function that counts number of rows Usage: COUNT(<rows>) Example: SELECT COUNT(player_id) FROM actions;
COUNT() player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) SELECT COUNT(player_id) FROM actions; COUNT(player_id) 6
How do I? player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) How do I get the number of unique players? SELECT COUNT(DISTINCT(player_id)) FROM actions COUNT(DISTINCT(player_id)) 2
SELECT * SELECT * returns all rows Example: SELECT * FROM actions; player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8)
WHERE Specifies constraints Example: SELECT * FROM actions WHERE time>20;
WHERE player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) SELECT * FROM actions WHERE time>20 player_id quest_id action_id time detail 1 0 2 78 (2, 1) 1 1 2 80 (3, 8)
WHERE Specifies constraints Example: SELECT * FROM actions WHERE time>20; Can combine WHERE constraints with AND: SELECT * FROM actions WHERE time<15 AND player_id=0;
How do I? player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) Count # of actions with id=2? SELECT COUNT(*) FROM actions WHERE action_id=2;
How do I? player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) Count # of players who had an action with id=1? SELECT COUNT(DISTINCT(player_id)) FROM actions WHERE action_id=1;
How do I? player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) Count # of players who performed an action at (2,x)? Can t do this yet.
LIKE Specifies looser constraints: _ matches a single character % matches any number of characters Example: SELECT * FROM actions WHERE detail LIKE (2,_) ;
WHERE player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) SELECT * FROM actions WHERE detail LIKE (2,_) ; player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 1 0 2 78 (2, 1)
How do I? player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) Count # of players who performed an action in quest #1 at (x,8) SELECT COUNT(DISTINCT(player_id)) FROM actions WHERE quest_id=1 AND detail LIKE '(_,8)';
How do I actions players player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) player_id player_info 0 Windows 1 Linux Get all actions performed on Windows?
INNER JOIN Merges tables Example: SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id;
actions player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) players player_id player_info 0 Windows 1 Linux SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id; player_id quest_id action_id time detail player_id player_info 0 0 0 14 (2, 2) 0 Windows 0 0 1 16 (2, 4) 0 Windows 0 0 2 19 (1, 3) 0 Windows 0 1 2 20 (1, 1) 0 Windows 1 0 2 78 (2, 1) 1 Linux 1 1 2 80 (3, 8) 1 Linux
actions player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) players player_id player_info 0 Windows 1 Linux SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id WHERE players.player_info= Windows ; player_id quest_id action_id time detail player_id player_info 0 0 0 14 (2, 2) 0 Windows 0 0 1 16 (2, 4) 0 Windows 0 0 2 19 (1, 3) 0 Windows 0 1 2 20 (1, 1) 0 Windows
actions player_id quest_id action_id time detail 0 0 0 14 (2, 2) 0 0 1 16 (2, 4) 0 0 2 19 (1, 3) 0 1 2 20 (1, 1) 1 0 2 78 (2, 1) 1 1 2 80 (3, 8) players player_id player_info 0 Windows 1 Linux Count the # of actions that happened on Linux at (2,x)? SELECT COUNT(*) FROM actions INNER JOIN players ON players.player_id=actions.player_id WHERE player_info='linux' AND detail LIKE '(2,_)'; Count the # of unique players that played on Windows and performed an action after time=15? SELECT COUNT(DISTINCT(players.player_id)) FROM actions INNER JOIN players ON players.player_id=actions.player_id WHERE player_info='windows' AND actions.time>15;
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
Four tables Users Sessions users player_pageload_log Tasks Actions player_quest_log player_action_log
Users: users user_id user_info user ID (automatic) user details (if you provided them)
Sessions: player_pageload_log client_timestamp log_id user_id server_timestamp game_id version_id session_id when the client recorded the event overall ID; continually increments user ID (automatic) when the server recorded the event your game ID your version ID ID for this play session (automatic)
Tasks: player_quest_log log_quest_id quest_id log_quest_ts user_id game_id version_id dynamic_quest_id quest_detail session_seq_id session_id client_timestamp level_end_timestamp overall ID; continually increments ID for the task/level/quest when the server recorded the event user ID (automatic) your game ID your version ID unique ID for this specific quest instance quest details (if you provided them) which task in this session ID for this play session (automatic) when the client recorded the event when the client finished the task
Actions: player_action_log client_timestamp log_id game_id quest_id user_id action_id action_detail log_timestamp session_seq_id quest_seq_id when the client recorded the event overall ID; continually increments your game ID ID for this task/level/quest user ID (automatic) ID for this action action details (if you provided them) when the server recorded the event which action in this session which action in this task
Today Basic MySQL How the tables are implemented on GDIAC Open office hours