且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL多列ASC命令

更新时间:2023-02-02 22:32:43

升序是大多数(如果不是全部)数据库的默认,因此您的陈述有点像在这方面 weird ,但是,您可以通过向其添加说明符ASCDESC来为每个单独的列指定顺序.

Ascending order is the default for most (if not all) DBMS's so your statement is kind of weird in that respect but nevertheless, you can specify an order for each individual column by adding the specifier ASC or DESC to it.

您的陈述将变为

SELECT  title
        , project_index 
FROM    projectdetail 
WHERE   project_index BETWEEN 1 AND 6 
ORDER BY 
        title ASC
        , project_index ASC

修改

如@Arvo& @Dems,当前您在title上按 first 排序,在project_index上对相同的标题进行排序.如果要先对project_index排序,则必须将其首先放在ORDER BY子句中.

As been mentioned by @Arvo & @Dems, currently you are sorting first on title and for identical titles on project_index. If you want your project_index sorted first, you have to place it first in the ORDER BY clause.

您的陈述就变成

SELECT  title
        , project_index 
FROM    projectdetail 
WHERE   project_index BETWEEN 1 AND 6 
ORDER BY 
        project_index ASC
        , title ASC

,并且由于ASC是默认的排序顺序,因此您可以将它们全部省略

and because ASC is the default sort order, you can omit them alltogether

SELECT  title
        , project_index 
FROM    projectdetail 
WHERE   project_index BETWEEN 1 AND 6 
ORDER BY 
        project_index
        , title