0

这是我的查询

$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 的行,hard_incent > '0'那么它显示的行首先等于 0,因为它们是ASC有序的。

4

1 回答 1

1

利用:

ORDER BY hard_incent <= 0, hard_incent ASC, date_added DESC

对于大于 0 的行,第一个比较为 0,对于小于或等于 0 的行,为 1,因此它将首先显示较大的行。然后在这两组中,它将按hard_incent和排序date_added

于 2013-09-19T21:52:29.637 回答