MySQL多列ASC命令 [英] MySQL multiple column asc order

查看:199
本文介绍了MySQL多列ASC命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按升序运行此查询:

I am trying to run this query in ascending order:

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

我需要按升序排列两列,但是上面的查询返回的结果只按ASC列显示一列.

I need two columns in ascending order, but the above query returns results with only one column in ASC order.

推荐答案

升序是大多数(如果不是全部)数据库的默认,因此您的陈述有点像在这方面 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

这篇关于MySQL多列ASC命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆