mysql asc,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;

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

解决方案

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.

Your statement then would become

SELECT title

, project_index

FROM projectdetail

WHERE project_index BETWEEN 1 AND 6

ORDER BY

title ASC

, project_index ASC

Edit

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.

Your statement then becomes

SELECT title

, project_index

FROM projectdetail

WHERE project_index BETWEEN 1 AND 6

ORDER BY

project_index ASC

, title 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值