加入多个表并按组分组

时间:2016-05-10 15:57:26

标签: sql-server

我正在使用4表连接创建查询我想使用airbill进行分组我试过这个,但它没有给出确切的输出

SELECT Item.Name, TLSaleOrder.Description As SoldAs, Containers.NetWeight, UnitsOfMeasure.UOM, Containers.ContainerNumber, Containers.SealNumber,SupplierInvoice.airbill
FROM Containers 
LEFT OUTER JOIN Item ON Containers.ItemID = Item.ID 
LEFT OUTER JOIN UnitsOfMeasure ON UnitsOfMeasure.ID = Containers.UOM 
LEFT OUTER JOIN TransactionHeader SupplierInvoice ON SupplierInvoice.ID=Containers.SupplierInvoiceID 
LEFT OUTER JOIN TransactionLine TLSupplierInvoice ON TLSupplierInvoice.TransactionID = SupplierInvoice.ID AND TLSupplierInvoice.LineType='Detail' AND TLSupplierInvoice.LineSubType='Product' 
LEFT OUTER JOIN TransactionHeader SaleOrder ON SaleOrder.ID = TLSupplierInvoice.SOTransID 
LEFT OUTER JOIN TransactionLine TLSaleOrder ON TLSaleOrder.TransactionID = SaleOrder.ID AND TLSaleOrder.LineType='Detail' AND TLSaleOrder.LineSubType='Product' 
LEFT OUTER JOIN TransactionHeader Invoice ON Invoice.ParentTransactionID = SaleOrder.ID 
WHERE Invoice.ID= 13 
group by SupplierInvoice.airbill

0 个答案:

没有答案