Skip to content

Commit 79ea98e

Browse files
refactor 578
1 parent ee55df1 commit 79ea98e

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

Diff for: database/_578.sql

-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
--578. Get Highest Answer Rate Question
2-
--
3-
--Get the highest answer rate question from a table survey_log with these columns: uid, action, question_id, answer_id, q_num, timestamp.
4-
--
5-
--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.
6-
--
7-
--Write a sql query to identify the question which has the highest answer rate.
8-
--
9-
--Example:
10-
--Input:
11-
--+------+-----------+--------------+------------+-----------+------------+
12-
--| uid | action | question_id | answer_id | q_num | timestamp |
13-
--+------+-----------+--------------+------------+-----------+------------+
14-
--| 5 | show | 285 | null | 1 | 123 |
15-
--| 5 | answer | 285 | 124124 | 1 | 124 |
16-
--| 5 | show | 369 | null | 2 | 125 |
17-
--| 5 | skip | 369 | null | 2 | 126 |
18-
--+------+-----------+--------------+------------+-----------+------------+
19-
--Output:
20-
--+-------------+
21-
--| survey_log |
22-
--+-------------+
23-
--| 285 |
24-
--+-------------+
25-
--Explanation:
26-
--question 285 has answer rate 1/1, while question 369 has 0/1 answer rate, so output 285.
27-
--Note: The highest answer rate meaning is: answer number's ratio in show number in the same question.
28-
291
SELECT question_id AS 'survey_log' FROM survey_log GROUP BY question_id ORDER BY
302
COUNT(answer_id) / COUNT(case when survey_log.action =
313
'show' then survey_log.action else null end) DESC LIMIT 0,1

0 commit comments

Comments
 (0)