0% found this document useful (0 votes)
35 views1 page

Solution 1

The document presents two SQL solutions for retrieving the most frequently answered survey question from a database. Both solutions group the results by question_id and order them based on the ratio of answered questions to the number of times the question was shown. The first solution uses COUNT with an IF statement, while the second utilizes SUM with a CASE statement for the same purpose.

Uploaded by

ganesan r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Solution 1

The document presents two SQL solutions for retrieving the most frequently answered survey question from a database. Both solutions group the results by question_id and order them based on the ratio of answered questions to the number of times the question was shown. The first solution uses COUNT with an IF statement, while the second utilizes SUM with a CASE statement for the same purpose.

Uploaded by

ganesan r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#Solution 1:

SELECT question_id AS survey_log

FROM survey_log

GROUP BY question_id

ORDER BY COUNT(answer_id)/COUNT(IF(action = "show",1,0)) DESC

LIMIT 1

#Solution 2:

SELECT question_id AS survey_log

FROM survey_log

GROUP BY question_id

ORDER BY COUNT(answer_id)/SUM(CASE WHEN action = "show" THEN 1 ELSE 0 END)) DESC

LIMIT 1

You might also like