大家好,你们能帮我吗? 请在下面的图像中找到输入和输出数据 因此,我需要编写sql请求以仅显示每个competent_question_id中的最大日期,并且还显示具有该日期的competent_answer_id的值(我也按response_id分组,但我将其隐藏在此处)
提前谢谢
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
最佳答案
尝试以下查询以获得所需的结果。
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
关于mysql - sql 请求最大分组依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47513538/