578. 查询回答率最高的问题

即一个问题show之后,可能是被answer了,也可能是被skip了,所以求回答率。
其实思路都是一致的,求出回答次数/出现次数即可
题解一

SELECT question_id as survey_log
FROM
(
SELECT question_id,
       SUM(CASE WHEN action = 'answer' THEN 1 ELSE 0 END) AS num_answer,
       SUM(CASE WHEN action = 'show' THEN 1 ELSE 0 END) AS num_show  
	   FROM survey_log
	   GROUP BY question_id
) AS n
ORDER BY (num_answer / num_show) DESC
LIMIT 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值