LeetCode MySQL 578. 查询回答率最高的问题
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL 578. 查询回答率最高的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
從 survey_log 表中獲得回答率最高的問題,
survey_log 表包含這些列:id, action, question_id, answer_id, q_num, timestamp。
請編寫 SQL 查詢來找到具有最高回答率的問題。
示例:
輸入: +------+-----------+--------------+------------+-----------+------------+ | id | action | question_id | answer_id | q_num | timestamp | +------+-----------+--------------+------------+-----------+------------+ | 5 | show | 285 | null | 1 | 123 | | 5 | answer | 285 | 124124 | 1 | 124 | | 5 | show | 369 | null | 2 | 125 | | 5 | skip | 369 | null | 2 | 126 | +------+-----------+--------------+------------+-----------+------------+ 輸出: +-------------+ | survey_log | +-------------+ | 285 | +-------------+ 解釋: 問題 285 的回答率為 1/1,而問題 369 回答率為 0/1,因此輸出 285 。提示:回答率最高的含義是:同一問題編號中回答數占顯示數的比例最高。
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/get-highest-answer-rate-question
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
# Write your MySQL query statement below select question_id survey_log from survey_log group by question_id having sum(answer_id is not null)/count(*) = (select sum(answer_id is not null)/count(*) prectfrom survey_loggroup by question_idorder by prect desc limit 1 )我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode MySQL 578. 查询回答率最高的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [Kesci] 预测分析 · 客户购买预
- 下一篇: LeetCode 431. 将 N 叉树