题目:
活动表 Activity
:
写一条 SQL 查询语句获取每位玩家 第一次登陆平台的日期。
查询结果的格式如下所示:
解题思路:
方法一:使用dense_rank() over(partition by ... order by ...):将登录时间按用户id进行分组然后升序排序,最后筛选出排序后为1的数据。
1 select player_id,event_date as first_login 2 from ( 3 select player_id,event_date,dense_rank() over(partition by player_id order by event_date) as rnk 4 from Activity 5 ) as a 6 where rnk = 1;
方法二:使用聚合函数min()和group by
1 select player_id,min(event_date) as first_login 2 from Activity 3 group by player_id;
标签:date,Activity,id,力扣,player,MySQL,511,event,select From: https://www.cnblogs.com/liu-myu/p/17238772.html