提前谢谢
SELECT response_id, competence_question_id, competence_answer_id, MAX(date_created)
FROM competence_vote_history
WHERE response_id = 53178
GROUP BY response_id, competence_question_id, competence_answer_id
ORDER BY response_id, competence_question_id
答案 0 :(得分:0)
尝试以下查询以获得所需的结果。
SELECT competence_question_id, competence_answer_id, date_created, answer_value
FROM competence_vote_history i
WHERE response_id = 53178
AND date_created = (
SELECT MAX(date_created)
FROM competence_vote_history
WHERE response_id = i.response_id
AND competence_question_id = i.competence_question_id)
ORDER BY response_id, competence_question_id
答案 1 :(得分:0)
如果date_created列没有重复日期,那么您可以使用派生表(其中获取compe_question_id的最大值(date_created))连接回原始表:
SELECT V.*
FROM (
SELECT competence_question_id, MAX(date_created) AS MAXdate_created
FROM competence_vote_history
WHERE response_id = 53178
GROUP BY competence_question_id
) AS dT INNER JOIN competence_vote_history V on dT.competence_question_id = V.competence_question_id
AND dT.MAXdate_created = V.date_created
ORDER BY response_id, competence_question_id