2022-12-13:游戏玩法分析 I。写一条 SQL 查询语句获取每位玩家 第一次登陆平台的日期。
----------- -------------
| player_id | first_login |
----------- -------------
| 1 | 2016-03-01 |
| 2 | 2017-06-25 |
| 3 | 2016-03-02 |
----------- -------------
代码语言:javascript复制DROP TABLE IF EXISTS `activity`;
CREATE TABLE `activity` (
`player_id` int(11) NOT NULL,
`device_id` int(11) NOT NULL,
`event_date` date NOT NULL,
`games_played` int(11) NOT NULL,
UNIQUE KEY `player_id` (`player_id`,`event_date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `activity` VALUES ('1', '2', '2016-03-01', '5');
INSERT INTO `activity` VALUES ('1', '2', '2016-05-02', '6');
INSERT INTO `activity` VALUES ('2', '3', '2017-06-25', '1');
INSERT INTO `activity` VALUES ('3', '1', '2016-03-02', '0');
INSERT INTO `activity` VALUES ('3', '4', '2018-07-03', '5');
答案2022-12-13:
代码语言:javascript复制SELECT player_id, MIN(event_date) AS first_login FROM Activity GROUP BY player_id;