代码拉取完成,页面将自动刷新
# $578. 查询回答率最高的问题
# https://leetcode-cn.com/problems/get-highest-answer-rate-question/
# SQL架构
Create table If Not Exists SurveyLog (id int, action varchar(255), question_id int, answer_id int, q_num int, timestamp int);
Truncate table SurveyLog;
insert into SurveyLog (id, action, question_id, answer_id, q_num, timestamp) values ('5', 'show', '285', null, '1', '123');
insert into SurveyLog (id, action, question_id, answer_id, q_num, timestamp) values ('5', 'answer', '285', '124124', '1', '124');
insert into SurveyLog (id, action, question_id, answer_id, q_num, timestamp) values ('5', 'show', '369', null, '2', '125');
insert into SurveyLog (id, action, question_id, answer_id, q_num, timestamp) values ('5', 'skip', '369', null, '2', '126');
# Write your MySQL query statement below
select
question_id as survey_log
from
(
select
question_id,
sum(if(action = 'answer', 1, 0)) as answercnt,
sum(if(action = 'show', 1, 0)) as showcnt
from
SurveyLog
group by
question_id
) tmp
order by
(answercnt / showcnt) desc
limit
1;
# clean-up
drop table SurveyLog;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。