Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-0578.test 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-05-01 21:49 +08:00 . fix lc-0577.test lc-0578.test
# $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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助