0

我可以使选定的记录出现在排序查询的开头:

$sql = "SELECT meetID, meetingTitle
FROM meetings
ORDER BY meetingTitle = 'Other Meetings' DESC, meetingTitle DESC";

这迫使“其他会议”位于字母数组输出的顶部。我希望它在底部。然后我可以使用 array_reverse 将它放在输出数组的末尾,但我正在寻找一种直接使用 MySQL 查询的方法。那可能吗?

4

2 回答 2

2

更改ASCDESC

$sql = "SELECT meetID, meetingTitle
        FROM meetings
        ORDER BY meetingTitle = 'Other Meetings' ASC, meetingTitle DESC";

的值meetingTitle = 'Other Meetings'适用1于其他值。因此,如果您首先要其他值,则要领先于,这就是 ASCending 顺序。Other Meetings001

于 2017-02-24T23:10:49.043 回答
0
    SELECT meetID, meetingTitle FROM  meetings
    ORDER BY 
    CASE WHEN meetingTitle = 'Other Meetings' THEN 2 ELSE 1 END, meetingTitle DESC
于 2017-02-24T23:10:38.477 回答