今天写一个查询语句,需要查询CODE、总数量、发货量、未发货量,需要用嵌套查询 在此记录下语法SQL功底有待提升
--查询 嵌套
select T.Code,T.DeliveryCount,T.TotleCount,T.TotleCount-T.DeliveryCount as NoDelivery from(SELECT dbo.[Order].Code, COUNT(dbo.Courier.CourierCode1) AS DeliveryCount, COUNT(dbo.Courier.CourierID) AS TotleCount
FROM dbo.Courier INNER JOINdbo.OrderSub ON dbo.Courier.OrderSubID = dbo.OrderSub.OrderSubID INNER JOINdbo.[Order] ON dbo.OrderSub.OrderID = dbo.[Order].OrderID
WHERE (dbo.[Order].ReceiverTEL = ' 电话' AND (dbo.[Order].IsRefund = 0) OR(dbo.[Order].IsRefund = 0) AND (dbo.[Order].BuyerPhone = '电话')
GROUP BY dbo.[Order].Code
)
as T