注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
不知为何我写的就是结果不对,online compare也比较了,基本和答案没有差别,求解
这是我的mysql代码
- SELECT question_id AS survey_log
- from (
- select(
- sum(
- case when 'action' like 'answer' then 1
- else 0
- end
- )
- /
- sum(
- case when 'action' like 'show' then 1
- else 0
- end
- )
- ) as rate,question_id
- from survey_log
- group by question_id
- order by rate desc
- limit 1
- )x
复制代码
答案:Wrong answer
- {"headers": {"survey_log": ["id", "action", "question_id", "answer_id", "q_num", "timestamp"]},"rows": {"survey_log": [[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:{"headers": ["survey_log"], "values": [[369]]}
expected:{"headers": ["survey_log"], "values": [[285]]}
这个答案代码:
- select question_id as survey_log
- from(
- select (
- sum(
- case when `action` like 'answer' then 1
- else 0
- end
- )
- /
- sum(
- case when `action` like 'show' then 1
- else 0
- end
- )
- ) as rate,question_id
- from survey_log
- group by question_id
- order by rate desc
- limit 1
- ) x
复制代码
|