在这种情况下如何 mySQL ORDER BY

How to mySQL ORDER BY in this case

我有这个 table 并试图显示数据 ORDER BY 但基于多列。

Table:

_______________________________________________
id | title | dis | cityid | dist | queue | date
_______________________________________________
1  |  abc  | 1   |  1     |  0   |  1    | 2017
2  |  cde  | 1   |  1     |  0   |  1    | 2017
3  |  efg  | 1   |  1     |  0   |  1    | 2017
4  |  ghi  | 1   |  1     |  0   |  1    | 2017
5  |title1 | 1   |  1     |  1   |  1    | 2017
6  | title2| 2   |  1     |  2   |  2    | 2017
7  | abc   | 2   |  1     |  0   |  2    | 2017
8  | cde   | 2   |  1     |  0   |  2    | 2017
9  | efg   | 2   |  1     |  0   |  2    | 2017

目标:

titl1
abc
cde
efg
ghi
titl12
abc
cde
efg

查询:

$sql = "SELECT * FROM district ORDER BY title ASC, queue ASC";

我也试过:

$sql = "SELECT * FROM district ORDER BY title ASC, dist ASC";

但是none这些作品,有什么建议吗? 我也可以自由地 add/remove 列或更改数据(如 dist、queue)来实现这个。

dis = 1的数据是title 1的子组,dis = 2的是title 2的子组,title1和2是hading

第一次查询结果为:

    abc
    cde
    efg
    ghi
    titl1
    titl12
    abc
    cde
    efg

首先您想按主要组排序 dis 并首先显示最低的:

ORDER BY dis ASC

然后,在该排序中,您希望对具有相同 dis 的所有项进行排序,以首先获得 headers(其中 dist 不为零):

ORDER BY dis ASC, dist DESC

最后,您希望其余部分按字母顺序排列:

ORDER BY dis ASC, dist DESC, title ASC