1
我想加入这两个查询:加入两个查询
InventoryItemID,似乎无法使其工作。我已经尝试了很多解决方案,但无法围绕它解决问题。我正在使用Microsoft SQL。
select t1.itemcode, t1.Description, t1.MinimumQuantity, t1.QuantityInStore, t2.qty as OnOrder, t1.InventoryItemID
from
(
select i.InventoryItemID, i.ItemCode, i.Description, MinimumQuantity, ii.QuantityInStore
from InventoryInfo i
inner join InventoryStoreInfo ii
on i.InventoryItemID = ii.inventoryitemid
inner join PurchaseOrderItemInfo p
on ii.InventoryItemID = p.InventoryItemID
inner join PurchaseOrderInfo po
on p.PurchaseOrderID = po.PurchaseOrderID
inner join VendorInfo v
on po.VendorID = v.VendorID
where InventoryCategoryID = '1'
and i.IsActive = '1'
) as t1
left join
(
select InventoryItemID, sum(Quantity) as QTY, Description
from PurchaseOrderItemInfo p
inner join PurchaseOrderInfo po
on p.PurchaseOrderID = po.PurchaseOrderID
where p.status = '0'
group by InventoryItemID, Description
) as t2
on t1.inventoryitemid = t2.inventoryitemid
和
select pi.InventoryItemID, v.VendorName, max(p.PODateTime) as latest
from PurchaseOrderItemInfo pi
inner join PurchaseOrderInfo p
on pi.PurchaseOrderID = p.PurchaseOrderID
inner join InventoryInfo i
on pi.InventoryItemID = i.InventoryItemID
inner join VendorInfo v
on p.VendorID = v.VendorID
group by pi.inventoryitemid, p.PODateTime,i.description, v.VendorName
order by latest desc
这是什么问题? –
您是否在寻找select * from(查询1转到这里)q1 JOIN(查询2转到这里)q2 on q1.InventoryItemID = q2.InventoryItemID' – Blorgbeard
我提供的两个查询都有共同的inventoryitemid,我想将查询2中的日期添加到查询1 – JeffreyLazo