gpt4 book ai didi

mysql - 分组顺序 - SQL

转载 作者:行者123 更新时间:2023-11-29 04:50:21 25 4
gpt4 key购买 nike

我有一个包含 3 个字段的表,比如:

roll varchar(100)

marks int (10) // can be 0 5 or 10

time anyTimeFormat

//time stores the time of passing the exam.

我需要做的是升序排序,完成时间,我可以做到

ORDER by time ASC

但是,我需要按升序排序,同时,根据分数分组记录,即得分为10的人,最先完成的,等等。

我试过 GROUP BY,但知道它行不通。欢迎对此提供任何帮助。

注意:我使用 mysql。 PHP 是前端。

示例数据:

roll        marks        time

1 10 2012-09-07 15:03:39
2 10 2012-09-07 15:03:42
3 10 2012-09-07 15:03:17
4 10 2012-09-07 15:03:20
5 5 2012-09-07 15:03:11

预期输出::

// I want those with 10 marks to be displayed first.

roll marks time

1 10 2012-09-07 15:03:17
2 10 2012-09-07 15:03:20
3 10 2012-09-07 15:03:39
4 10 2012-09-07 15:03:42
5 5 2012-09-07 15:03:11

最佳答案

使用:

ORDER BY marks DESC, time ASC

或者换句话说,您按分数排序是因为您希望最高分排在第一位,然后对于同等分数,按时间排序以便首先显示第一个完成者。

关于mysql - 分组顺序 - SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12437736/

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