我有两张桌子:
第一个:table_a
id | orderid
1 123
2 456
...
第二:table_b
orderid | status | date
123 2 1380566559
123 4 1380566561
123 6 1380566563
仅当 orderid 的状态为 2 并且在我的表中没有状态 4 和 6 时,我才想从 table_a 返回 orderid 行...
我试过没有成功:(
SELECT DISTINCT(a.orderid)
FROM table_a AS a
INNER JOIN table_b AS b
INNER JOIN table_b AS c
INNER JOIN table_b AS d
ON a.orderid = b.orderid
WHERE b.status = 2 AND
c.status != 4 AND
d.status != 6;