订单实体有OneToMany OrderStatsu,所以任何订单都有很多状态,我想查找最后状态= x的所有订单。
我的查询看起来像这样(和工作)
SELECT o.id, os.status_id FROM orders o
LEFT JOIN(
SELECT *
FROM order_status
GROUP BY orders_id DESC
) AS os
ON o.id = os.orders_id
但我想把它作为对象。
答案 0 :(得分:0)
首先GROUP BY orders_id DESC
语法错误。您可以更改
SELECT o.id, os.status_id
FROM orders o
LEFT JOIN(SELECT status_id, orders_id,
GROUP_CONCAT(statuses ORDER BY statuses DESC) AS Status
FROM order_status
GROUP BY orders_id) os
ON o.id = os.orders_id
WHERE LEFT(os.Status) = 'X';