如何让SQL查询排名?
考虑到最佳时间和得分,如何获得有史以来最好的排名?假设用户赢了几次,如何计算最佳用户赢了多少次以及平均赢的时间是多少?
+----------------+----------------+--------+-----------------------+
| user_id | quiz_id | score | finish |
+----------------+----------------+--------+-----------------------+
| 1 | 1 | 1 | 2011-05-18 21:39:00 |
| 2 | 1 | 1 | 2011-05-18 21:43:10 |
| 3 | 1 | 0 | 2011-05-18 21:40:55 |
| 1 | 2 | 1 | 2011-05-18 22:51:57 |
| 2 | 2 | 1 | 2011-05-18 22:21:37 |
| 3 | 2 | 0 | 2011-05-18 22:22:48 |
| 4 | 2 | 1 | 2011-05-18 22:58:14 |
+----------------+----------------+--------+-----------------------+
How to get the ranking best of the best ever, considering the best time and the score? Assuming that user won a few times, how to count how many times best user wins and what is the average time of this wins?
+----------------+----------------+--------+-----------------------+
| user_id | quiz_id | score | finish |
+----------------+----------------+--------+-----------------------+
| 1 | 1 | 1 | 2011-05-18 21:39:00 |
| 2 | 1 | 1 | 2011-05-18 21:43:10 |
| 3 | 1 | 0 | 2011-05-18 21:40:55 |
| 1 | 2 | 1 | 2011-05-18 22:51:57 |
| 2 | 2 | 1 | 2011-05-18 22:21:37 |
| 3 | 2 | 0 | 2011-05-18 22:22:48 |
| 4 | 2 | 1 | 2011-05-18 22:58:14 |
+----------------+----------------+--------+-----------------------+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到最近的完成日期时间来获得最佳分数非常容易。
总体
对于每个测验
对于每个用户
我不确定您所说的用户获胜数量是什么意思。胜利意味着什么?与平均时间相同;这里没有足够的信息来帮助您解决这两个问题。
To get the best score considering the latest finish datetime is pretty easy.
Overall
For Each Quiz
For Each User
I'm not sure what you mean by number of user wins. What signifies a win? Same with average time; there's not enough information here to help you with these two questions.