当前位置: 代码迷 >> 综合 >> SQL_ 嵌套查询
  详细解决方案

SQL_ 嵌套查询

热度:75   发布时间:2024-01-26 13:18:53.0

今天写一个查询语句,需要查询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
  相关解决方案