如何基于两个不同的列进行ORDER BY [英] How to ORDER BY based on two different columns
本文介绍了如何基于两个不同的列进行ORDER BY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个5列的表格.当我列出表时,我想按一列排序,以便将类型分组在一起,然后按字母顺序对它们进行排序,以便于查找.
I have a table with 5 columns. When I list the table, I want to order by one column so that the types are grouped together and then order them alphabetical so that they are easy to find.
是否可以通过两个不同的列来ORDER
?
Is it possible to ORDER
by two different columns?
这是我当前的选择:
$query_rs_cms = "SELECT * FROM games ORDER BY type ASC";
我想我正在寻找的东西是这样的:
I guess what I'm looking for is something like:
SELECT *
FROM games
ORDER BY type THEN ORDER BY title ASC";
推荐答案
您可以通过列名或返回的列号指定ORDER BY.
You can specify the ORDER BY by either the column name or by the column number of the return.
所以您可以这样做:
SELECT * FROM games ORDER BY Type, Title
或类似的东西
SELECT Type, Title, Column1, Column2 FROM games ORDER BY 1, 2
您还可以进行升序和降序.因此,如果您想输入Type Descending但Title Ascending:
You can also do ascending and descending. So if you wanted Type Descending but Title Ascending:
SELECT * FROM games ORDER BY Type DESC, Title ASC
这篇关于如何基于两个不同的列进行ORDER BY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文