这是我的查询
$offers_with_limit = $db->query("
SELECT *
FROM `offers`
WHERE `countries` LIKE '%'?'%'
AND `category` = '$query2'
AND NOT EXISTS
(SELECT *
FROM completed
WHERE completed.offer_id = offers.id
AND completed.user = ?)
AND NOT EXISTS
(SELECT *
FROM pending
WHERE pending.offer_id = offers.id
AND pending.user = ?)
AND NOT EXISTS
(SELECT *
FROM ignored
WHERE ignored.offer_id = offers.id
AND ignored.user = ?)
AND `active` = '1'
AND `hard_incent` > '0'
ORDER BY `hard_incent` ASC,
`date_added` DESC LIMIT $startpoint,$limit
");
显然,它只会显示大于0的行,但我还需要它继续显示大于等于0的行之后的行,如果我不添加{{1然后它显示首先等于0的行,因为它们是hard_incent > '0'
顺序。
答案 0 :(得分:1)
使用:
ORDER BY hard_incent <= 0, hard_incent ASC, date_added DESC
对于大于0的行,第一次比较将为0;对于小于或等于0的行,第一次比较将为1,因此它将首先显示更大的行。然后在这两个集合中,它将按hard_incent
和date_added
排序。