高效 SELECT q.ID_ANSWER, q.ID_QUESTION, q.CONTENT, q.UPVOTE_TOTE, q.IS_ADOPT, q.ID_USER, q.OPPOSE_TOTE, q.ANSWER_TIME, q.ACT_FLAG, q.SCORE, u.OFFICIAL_EXPERT, qs.TITLE, qs.ID_USER QUESTIONUSER, u.USER_NAME QUESTIONUSER_NAME, u.HEAD_IMAGE_URL QUESTIONUSER_IMGURL, qs.IS_SOLVED, qs.Date_Created QUESTION_TIME, qq.counts FROM KNOWLEDGE_Q_ANSWER q left join K_USER u on q.ID_USER = u.ID_USER left join KNOWLEDGE_QUESTION qs on q.id_question = qs.id_question left join (SELECT a.id_question, COUNT(a.id_answer)as counts FROM KNOWLEDGE_Q_ANSWER a group by a.id_question) qq on q.id_question=qq.id_question WHERE q.ACT_FLAG='Y' order by nvl(ANSWER_TIME,sysdate) desc
低效 SELECT q.ID_ANSWER, q.ID_QUESTION, q.CONTENT, q.UPVOTE_TOTE, q.IS_ADOPT, q.ID_USER, q.OPPOSE_TOTE, q.ANSWER_TIME, q.ACT_FLAG, q.SCORE, u.OFFICIAL_EXPERT, qs.TITLE, qs.ID_USER QUESTIONUSER, u.USER_NAME QUESTIONUSER_NAME, u.HEAD_IMAGE_URL QUESTIONUSER_IMGURL, qs.IS_SOLVED, qs.Date_Created QUESTION_TIME, (SELECT a.id_question, COUNT(a.id_answer)as counts FROM KNOWLEDGE_Q_ANSWER a group by a.id_question) coun FROM KNOWLEDGE_Q_ANSWER q left join K_USER u on q.ID_USER = u.ID_USER left join KNOWLEDGE_QUESTION qs on q.id_question = qs.id_question WHERE q.ACT_FLAG='Y' order by nvl(ANSWER_TIME,sysdate) desc