题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
--解决方案(1) WITHt1AS( SELECTquestion_id, IF(action='show', 1, 0) shown, IF(action='answer', 1, 0) answern, IF(action='skip', 1, 0) skipnFROMsurvey_log), t2AS( SELECTquestion_id, SUM(answern) OVER(PARTITIONBYquestion_id) sum_answer, SUM(shown) OVER(PARTITIONBYquestion_id) sum_showFROMt1), t3AS( SELECTquestion_id, sum_answer/sum_showrateFROMt2) SELECTquestion_idsurvey_logFROMt3WHEREquestion_idISNOTNULLORDERBYrateDESCLIMIT1--解决方案(2) selectAnswerCnt.question_idassurvey_logfrom(selectquestion_id, count(*) asanswer_cntfromsurvey_logwhereaction="answer"groupbyquestion_id) asAnswerCntjoin(selectquestion_id, count(*) asaction_cntfromsurvey_logwhereaction="show"groupbyquestion_id) asShowCntonAnswerCnt.question_id=ShowCnt.question_idorderbyAnswerCnt.answer_cnt/ShowCnt.action_cntdesclimit1; --解决方案(3) selectquestion_idassurvey_logfrom ( selectquestion_id, sum(if(action='answer', 1, 0)) asAnswerCnt, sum(if(action='show', 1, 0)) asShowCntfromsurvey_loggroupbyquestion_id) astblorderby (AnswerCnt/ShowCnt) desclimit1; --解决方案(4) selectquestion_idassurvey_logfromsurvey_loggroupbyquestion_idorderbysum(if(action='answer', 1, 0)) /sum(if(action='show', 1, 0)) desclimit1;