如何获取表中所有订单的列表,除了(已引用的订单和类型为-1)
订单表:
id | reference_id | type
----------------------------------
1 | | 1
----------------------------------
2 | | 1
----------------------------------
3 | 1 | -1
----------------------------------
就像是:
list = ArrayList();
if( order.type > 0 ){
if( order.id != other_order.reference_id )
list.add(order)
}
如何在 MySQL 语句中执行此操作?
此语句的结果也相同,但使用 JOIN....等:
select * from orders as a
where a.type > 0 AND not exists
(select * from orders as b where a.id = b.ref_id)
谢谢