我正在尝试按升序运行此查询:
SELECT title,project_index FROM projectdetail WHERE project_index BETWEEN 1 AND 6 ORDER BY title, project_index ASC;
我需要两列按升序排列,但上述查询只返回一个列按ASC顺序的结果。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
升序是大多数(如果不是全部)DBMS的默认排序方式,所以你的语句在这方面有点奇怪,但是无论如何,你可以通过在每个列上添加ASC或DESC来指定排序方式。
你的语句将变为:
SELECT title , project_index FROM projectdetail WHERE project_index BETWEEN 1 AND 6 ORDER BY title ASC , project_index ASC编辑
正如@Arvo和@Dems所提到的,你当前是首先按照标题排序,如果标题相同,则按照project_index排序。如果你想要project_index首先排序,你必须将它放在ORDER BY子句的第一位。
你的语句将变为:
SELECT title , project_index FROM projectdetail WHERE project_index BETWEEN 1 AND 6 ORDER BY project_index ASC , title ASC因为ASC是默认的排序顺序,所以你可以省略它们:
SELECT title , project_index FROM projectdetail WHERE project_index BETWEEN 1 AND 6 ORDER BY project_index , title