LeetCode MySQL 534. 游戏玩法分析 III
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL 534. 游戏玩法分析 III
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 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 | | 1 | 3 | 2017-06-25 | 1 | | 3 | 1 | 2016-03-02 | 0 | | 3 | 4 | 2018-07-03 | 5 | +-----------+-----------+------------+--------------+Result table: +-----------+------------+---------------------+ | player_id | event_date | games_played_so_far | +-----------+------------+---------------------+ | 1 | 2016-03-01 | 5 | | 1 | 2016-05-02 | 11 | | 1 | 2017-06-25 | 12 | | 3 | 2016-03-02 | 0 | | 3 | 2018-07-03 | 5 | +-----------+------------+---------------------+ 對于 ID 為 1 的玩家,2016-05-02 共玩了 5+6=11 個游戲,2017-06-25 共玩了 5+6+1=12 個游戲。 對于 ID 為 3 的玩家,2018-07-03 共玩了 0+5=5 個游戲。 請注意,對于每個玩家,我們只關心玩家的登錄日期。來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/game-play-analysis-iii
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
# Write your MySQL query statement below select a1.player_id, a1.event_date, sum(a2.games_played) games_played_so_far from Activity a1, Activity a2 where a1.player_id = a2.player_idand a1.event_date >= a2.event_date group by a1.player_id, a1.event_date我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode MySQL 534. 游戏玩法分析 III的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1229. 安排会议日
- 下一篇: LeetCode 1537. 最大得分(