SQL 求每位玩家最早登录的时间(分组求最大值,分组求最小值,分组求和)

https://leetcode.cn/problems/game-play-analysis-i/submissions/

 

Activity 表:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
+-----------+-----------+------------+--------------+
| 1 | 2 | 2016-03-01 | 5 |
| 1 | 2 | 2016-05-02 | 6 |
| 2 | 3 | 2017-06-25 | 1 |
| 3 | 1 | 2016-03-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
+-----------+-----------+------------+--------------+

 

select player_id,   min(event_date) first_login
from activity
group by player_id
 
 

select stock_name,
sum(if(operation = 'Buy',-price,price)) as capital_gain_loss
from Stocks
group by stock_name;

 

posted @ 2022-12-04 21:33  yinghualeihenmei  阅读(47)  评论(0编辑  收藏  举报