日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

LeetCode MySQL 1113. 报告的记录

發(fā)布時間:2024/7/5 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode MySQL 1113. 报告的记录 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

    • 1. 題目
    • 2. 解題

1. 題目

動作表:Actions

+---------------+---------+ | Column Name | Type | +---------------+---------+ | user_id | int | | post_id | int | | action_date | date | | action | enum | | extra | varchar | +---------------+---------+

此表沒有主鍵,所以可能會有重復(fù)的行。
action 字段是 ENUM 類型的,包含:('view', 'like', 'reaction', 'comment', 'report', 'share')
extra 字段是可選的信息(可能為 null),
其中的信息例如有:1.報告理由(a reason for report) 2.反應(yīng)類型(a type of reaction)

編寫一條SQL,查詢每種 報告理由(report reason)在昨天的報告數(shù)量。
假設(shè)今天是 2019-07-05。

查詢及結(jié)果的格式示例:

Actions table: +---------+---------+-------------+--------+--------+ | user_id | post_id | action_date | action | extra | +---------+---------+-------------+--------+--------+ | 1 | 1 | 2019-07-01 | view | null | | 1 | 1 | 2019-07-01 | like | null | | 1 | 1 | 2019-07-01 | share | null | | 2 | 4 | 2019-07-04 | view | null | | 2 | 4 | 2019-07-04 | report | spam | | 3 | 4 | 2019-07-04 | view | null | | 3 | 4 | 2019-07-04 | report | spam | | 4 | 3 | 2019-07-02 | view | null | | 4 | 3 | 2019-07-02 | report | spam | | 5 | 2 | 2019-07-04 | view | null | | 5 | 2 | 2019-07-04 | report | racism | | 5 | 5 | 2019-07-04 | view | null | | 5 | 5 | 2019-07-04 | report | racism | +---------+---------+-------------+--------+--------+Result table: +---------------+--------------+ | report_reason | report_count | +---------------+--------------+ | spam | 1 | | racism | 2 | +---------------+--------------+ 注意,我們只關(guān)心報告數(shù)量非零的結(jié)果。

來源:力扣(LeetCode) 鏈接:https://leetcode-cn.com/problems/reported-posts
著作權(quán)歸領(lǐng)扣網(wǎng)絡(luò)所有。商業(yè)轉(zhuǎn)載請聯(lián)系官方授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。

2. 解題

# Write your MySQL query statement below select extra report_reason, count(distinct post_id) report_count from Actions where action_date = '2019-07-04'and action = 'report'and extra is not null# and extra != null # 錯誤寫法 group by extra

561 ms


我的CSDN博客地址 https://michael.blog.csdn.net/

長按或掃碼關(guān)注我的公眾號(Michael阿明),一起加油、一起學(xué)習(xí)進步!

總結(jié)

以上是生活随笔為你收集整理的LeetCode MySQL 1113. 报告的记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。