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.
我有一个5列的表。当我列出表格时,我想按一列排序,以便将类型组合在一起,然后按字母顺序排列,以便于查找。
Is it possible to ORDER
by two different columns?
可以通过两个不同的列进行排序吗?
Here is my current select:
这是我目前的选择:
$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";
5 个解决方案
#1
25
You can specify the ORDER BY by either the column name or by the column number of the return.
您可以通过列名称或返回的列号指定ORDER BY。
So you could do:
所以你可以这样做:
SELECT * FROM games ORDER BY Type, Title
Or something like:
或类似的东西:
SELECT Type, Title, Column1, Column2 FROM games ORDER BY 1, 2
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
#2
13
SELECT * FROM games ORDER BY type, title
#3
11
ORDER BY type, title
ORDER BY类型,标题
You can do something like
你可以做点什么
ORDER BY type DESC, title ASC
ORDER BY类型DESC,标题ASC
too, if you need to.
如果你需要的话。
#4
4
Your order by can take a comma separated list of sorts, similar to your result set. Example:
您的订单可以采用逗号分隔的排序列表,类似于您的结果集。例:
select * from games order by type, entered_dt DESC, title ASC
#5
1
You are looking something like this :)
你看起来像这样:)
select * FROM games ORDER BY type, title
#1
25
You can specify the ORDER BY by either the column name or by the column number of the return.
您可以通过列名称或返回的列号指定ORDER BY。
So you could do:
所以你可以这样做:
SELECT * FROM games ORDER BY Type, Title
Or something like:
或类似的东西:
SELECT Type, Title, Column1, Column2 FROM games ORDER BY 1, 2
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
#2
13
SELECT * FROM games ORDER BY type, title
#3
11
ORDER BY type, title
ORDER BY类型,标题
You can do something like
你可以做点什么
ORDER BY type DESC, title ASC
ORDER BY类型DESC,标题ASC
too, if you need to.
如果你需要的话。
#4
4
Your order by can take a comma separated list of sorts, similar to your result set. Example:
您的订单可以采用逗号分隔的排序列表,类似于您的结果集。例:
select * from games order by type, entered_dt DESC, title ASC
#5
1
You are looking something like this :)
你看起来像这样:)
select * FROM games ORDER BY type, title