好的,我有这个代码:
SELECT
COUNT(a.auction_id) AS amount, a.owner_id
FROM
auctions AS a
INNER JOIN users AS u ON a.owner_id=u.user_id
LEFT JOIN winners AS w ON a.auction_id=w.auction_id
WHERE
FROM_UNIXTIME(a.start_time) BETWEEN '2013-07-01 00:00:00' AND '2013-07-31 23:59:59'
AND
a.owner_id IN (100012,100027,100030,100063,100065)
AND
a.active=1
AND
a.approved=1
AND
a.is_relisted_item=0
AND
a.is_draft=0
GROUP BY
a.owner_id
HAVING
amount > 4;
我想做的是像下面这样,但我只是不知道如何写它..
如果a.list_in = 'store' AND a.closed=1
那么它必须出现在获胜者表中才能包含在结果集中。所以基本上w.winner_id
不应该在winners
表中为 NULL 以便将其包含在结果中。
所以基本上,如果a.list_in = 'store'
这很好并且应该被包括在内,但是如果a.list_in = 'store' AND a.closed=1
它被包括在内w.winner_id
就不能为NULL。
我怎样才能做到这一点?