SELECT Inventory_Stock.id, Inventory_Stock.quantity, SUM(InventoryUsage.quantity)
,Inventory_Stock.quantity - SUM(InventoryUsage.quantity) AS Stock
FROM Inventory_Stock LEFT JOIN InventoryUsage ON Inventory_Stock.id = InventoryUsage.InventoryStock_id
WHERE Inventory_Stock.id = 26 OR
Inventory_Stock.id = 27
GROUP BY Inventory_Stock.id
ORDER BY Stock Asc
如何在 Symfony2 中编写上述代码,我想将其编写为原始查询
另外我正在使用 PageFanta 进行分页.. 所以上述查询的结果将进入分页。
关系是:
产品 (1 - 1) InventoryStock InventoryStock (1 - n) InventoryUsage