0

我的 mysql 查询有一个小问题。我只想显示订单状态不同于6. 但是 Theid_order有多个雕像,这意味着例如:

id_order = 8421
**has two statuses:**
id_order_state=8 and
id_order_state = 6.

这是我的表的示例:链接

我试过:

SELECT * FROM order_history WHERE id_order_state != 6 (but here I need more code that I can't handle)

谢谢你的帮助

编辑:订单 8421、8422 不应显示在结果中

4

3 回答 3

1

试试这个

> SELECT * FROM order_history WHERE id_order_state <> 6

或者

> SELECT * FROM order_history WHERE id_order_state NOT IN ( 6)
于 2013-03-08T11:06:17.253 回答
1

尝试:

SELECT i.* FROM order_history i
left join order_history e 
       on i.id_order = e.id_order and e.id_order_state = 6
WHERE  e.id_order_hitory is null
于 2013-03-08T11:12:35.927 回答
0

像这样?

SELECT * 
FROM order_history 
WHERE id_order NOT IN 
(SELECT id_order FROM order_history WHERE id_order_state = 6);
于 2013-03-08T11:15:49.557 回答