MySQL是否可以按顺序对两列进行排序?请参阅我的示例查询
<?php
$qResults = mysql_query("SELECT column1, column2 FROM tablename ORDER BY column1 ASC, column2");
//The initial data is these
Column 1 Column 2
7 24
18 3
2 25
9 23
17 8
1 15
10 19
20 4
11 6
16 5
//I want to sort it by this.
Column 1 Column 2
1 15
2 25
18 3
20 4
16 5
11 6
7 24
17 8
9 23
10 19
?><br>
按升序排序两列。这可能在mysql查询中吗?
答案 0 :(得分:1)
我终于得到了你想要的东西:
SELECT *
FROM torder
order by least(col1, col2), greatest(col1, col2)
答案 1 :(得分:0)
试试这个
$qResults = mysql_query("SELECT column1, column2 FROM tablename ORDER BY column1 ASC, column2 ASC");
它将对column1进行排序,然后对column1
中的column2进行排序答案 2 :(得分:0)
你可以试试这个:
$qResults = mysql_query("SELECT column1, column2 FROM tablename ORDER BY column1 ASC, column2 ASC");
参见: http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html