Ai
1 Star 0 Fork 0

徐长贺/Leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_578.sql 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
stevesun 提交于 2017-11-18 23:28 +08:00 . [N-0] add 578
--578. Get Highest Answer Rate Question
--
--Get the highest answer rate question from a table survey_log with these columns: uid, action, question_id, answer_id, q_num, timestamp.
--
--uid means user id; action has these kind of values: "show", "answer", "skip"; answer_id is not null when action column is "answer", while is null for "show" and "skip"; q_num is the numeral order of the question in current session.
--
--Write a sql query to identify the question which has the highest answer rate.
--
--Example:
--Input:
--+------+-----------+--------------+------------+-----------+------------+
--| uid | 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 |
--+------+-----------+--------------+------------+-----------+------------+
--Output:
--+-------------+
--| survey_log |
--+-------------+
--| 285 |
--+-------------+
--Explanation:
--question 285 has answer rate 1/1, while question 369 has 0/1 answer rate, so output 285.
--Note: The highest answer rate meaning is: answer number's ratio in show number in the same question.
SELECT question_id AS 'survey_log' FROM survey_log GROUP BY question_id ORDER BY
COUNT(answer_id) / COUNT(case when survey_log.action =
'show' then survey_log.action else null end) DESC LIMIT 0,1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/isulong/Leetcode.git
git@gitee.com:isulong/Leetcode.git
isulong
Leetcode
Leetcode
master

搜索帮助