LeetCode MySQL 512. 游戏玩法分析 II
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL 512. 游戏玩法分析 II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
Table: Activity
+--------------+---------+ | Column Name | Type | +--------------+---------+ | player_id | int | | device_id | int | | event_date | date | | games_played | int | +--------------+---------+ (player_id, event_date) 是這個表的兩個主鍵這個表顯示的是某些游戲玩家的游戲活動情況
每一行是在某天使用某個設備登出之前登錄并玩多個游戲(可能為0)的玩家的記錄
請編寫一個 SQL 查詢,描述每一個玩家首次登陸的設備名稱
查詢結果格式在以下示例中:
Activity table: +-----------+-----------+------------+--------------+ | 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 | +-----------+-----------+------------+--------------+Result table: +-----------+-----------+ | player_id | device_id | +-----------+-----------+ | 1 | 2 | | 2 | 3 | | 3 | 1 | +-----------+-----------+來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/game-play-analysis-ii
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
# Write your MySQL query statement below select a.player_id, a.device_id from Activity a,( select *, min(event_date) mindatefrom Activitygroup by player_id) t where a.player_id = t.player_id and a.event_date = t.mindateor
# Write your MySQL query statement below select player_id, device_id from activity where (player_id, event_date) in (select player_id, min(event_date)from activitygroup by player_id)我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode MySQL 512. 游戏玩法分析 II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 961. 重复 N 次
- 下一篇: LeetCode MySQL 1280.