-1

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查询中吗?

4

3 回答 3

1

我终于得到了你想要的:

SELECT *
FROM torder
order by least(col1, col2), greatest(col1, col2)
于 2013-10-15T04:52:28.297 回答
0

尝试这个

$qResults  =  mysql_query("SELECT column1, column2 FROM tablename ORDER BY column1 ASC, column2 ASC");

它将对 column1 进行排序,然后对 column1 中的 column2 进行排序

于 2013-10-15T04:47:36.887 回答
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

于 2013-10-15T04:48:57.203 回答