gpt4 book ai didi

MySQL : Get latest SCORE for each users where quiz_id = something

转载 作者:行者123 更新时间:2023-11-29 07:59:57 25 4
gpt4 key购买 nike

这是我的表格:

id     |     quiz_id     |     user_id     |     date_replied     |     score

1 1 1 2014-06-04 10:11:47 50
2 1 1 2014-06-04 20:52:53 90
3 1 5 2014-06-05 14:22:59 80
4 1 5 2014-06-06 18:23:41 70

我想要的是获取每个 user_id 的最新 score,例如 quiz_id 为 1。

因此,quiz_id = 1;它会返回:

id     |     quiz_id     |     user_id     |     date_replied     |     score

2 1 1 2014-06-04 20:52:53 90
4 1 5 2014-06-06 18:23:41 70

有没有办法在 MySQL 中做到这一点?

谢谢!

最佳答案

select t1.* 
from your_table t1
join
(
select user_id, max(date_replied) as mdate
from your_table
where quiz_id = 1
group by user_id
) t2 on t1.user_id = t2.user_id and t1.date_replied = t2.mdate

关于MySQL : Get latest SCORE for each users where quiz_id = something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24082325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com