网站开发职业前景,摄影网站导航,青岛哪家做网站的公司,山西网站制作方案文章目录1. 题目2. 解题1. 题目
从 survey_log 表中获得回答率最高的问题#xff0c; survey_log 表包含这些列#xff1a;id, action, question_id, answer_id, q_num, timestamp。
id 表示用户 id#xff1b;
action 有以下几种值#xff1a;show#xff…
文章目录1. 题目2. 解题1. 题目
从 survey_log 表中获得回答率最高的问题 survey_log 表包含这些列id, action, question_id, answer_id, q_num, timestamp。
id 表示用户 id
action 有以下几种值showanswerskip
当 action 值为 answer 时 answer_id 非空
而 action 值为 show 或者 skip 时 answer_id 为空
q_num 表示当前会话中问题的编号。请编写 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阿明一起加油、一起学习进步