Knowee
Questions
Features
Study Tools

Game Play Analysis IITable: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write a SQL query that reports the device that is first logged in for each player.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026232017-06-251312016-03-020342018-07-035Result table:player_iddevice_id122331Optionsselect device_idfrom Activity where (player_id, event_date) in (select player_id, min(event_date)from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in (select player_id, min(event_date)group by player_id);select player_id, device_idfrom Activity (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);Finish

Question

Game Play Analysis IITable: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write a SQL query that reports the device that is first logged in for each player.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026232017-06-251312016-03-020342018-07-035Result table:player_iddevice_id122331Optionsselect device_idfrom Activity where (player_id, event_date) in (select player_id, min(event_date)from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in (select player_id, min(event_date)group by player_id);select player_id, device_idfrom Activity (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);Finish

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct SQL query to get the device that is first logged in for each player is:

SELECT player_id, device_id
FROM Activity
WHERE (player_id, event_date) IN (
  SELECT player_id, MIN(event_date)
  FROM Activity
  GROUP BY player_id
);

Here's how it works:

  1. The subquery (SELECT player_id, MIN(event_date) FROM Activity GROUP BY player_id) is used to find the earliest login date for each player.

  2. The main query then selects the player_id and device_id from the Activity table where the player_id and event_date match those from the subquery. This gives us the device that each player first logged in with.

This problem has been solved

Similar Questions

Table: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write an SQL query that reports for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026132017-06-251312016-03-020342018-07-035Result table:player_idevent_dategames_played_so_far12016-03-01512016-05-021112017-06-251232016-03-02032018-07-035For the player with id 1, 5+6=11 games played by 2016-05-02, and 5+6+1=12 games played by 2017-06-25. For the player with id 3, 0+5=5 games played by 2018-07-03. Note that for each player we only care about the days when the player logged in.Optionsselect games_played_so_farfrom ( select player_id, event_date, @games := if(player_id = @player, @games + games_played, games_played) as games_played_so_far, @player := player_id from (select * from Activity order by player_id, event_date) as a, (select @player := -1, @games := 0) as tmp) as t;select player_id, event_date, games_played_so_farfrom ( select player_id, event_date, @games := if(player_id = @player, @games + games_played, games_played) as games_played_so_far, @player := player_id from (select * from Activity order by player_id, event_date) as a, (select @player := -1, @games := 0) as tmp) as t;select player_id, event_date, games_played_so_far select player_id, event_date, @games := if(player_id = @player, @games + games_played, games_played) as games_played_so_far, @player := player_id from (select * from Activity order by player_id, event_date) as a, (select @player := -1, @games := 0) as tmp) as t;select player_id, event_date, games_played_so_farfrom ( select player_id, event_date, @games := if(player_id = @player, @games + games_played, games_played) as games_played_so_far, @player := player_id from (select * from Activity order by player_id, event_date) as a,) as t;

Alter the Sessions Table: Add a new column SessionDuration to record the duration of each gaming session. The data type INTERVAL DAY TO SECOND is used to store durations.

You generate a report to show how many users are coming from various device types, like desktops and mobile phones, over the past 30 days.In this report, what is device type?A userA metricAn eventA dimension

Sports Craft Company has organized tournaments in multiple individual sports and invited top ranked players to play. Each tournament comprises of multiple matches in knock out format. Each match is played between two players.Problem Statement: Create the Player table as per information provided below:Column Name Data Type Constraint DescriptionPId INTEGER PRIMARY KEY Unique player Id is mandatory for every playerPName VARCHAR2(20) NOT NULL Player NameRanking INTEGER Player's ranking

WITH install AS ( SELECT el.user_id, el.create_time FROM event_logs el WHERE el.event_id = 'onboarding_login_view' AND el.referrer = 'plugin_installed' ) --first_usage_after_installed AS ( SELECT i.user_id, i.create_time, COALESCE(min(cr.event_time), toDateTime('1970-01-01 00:00:00')) AS first_event_time FROM install i LEFT JOIN chat_records cr ON i.user_id = cr.user_id WHERE cr.event_time > i.create_time GROUP BY i.user_id, i.create_time帮我修改代码,我要展现出用户安装后第一次使用的功能,即使没有使用也要

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.