根據查詢出各地訂單商品數量 group by

 

order訂單表,orderprduct訂單商品表,area地區表db

SELECT (a1.Name+a2.Name+a3.Name) AS areanaem,orderArea.AreaId,orderArea.number FROM (SELECT a.areaid,COUNT(a.areaid) AS number FROM (SELECT o.AreaId FROM order AS o LEFT JOIN dbo.OrderProduct AS op ON op.OrderNumber = o.Number WHERE o.areaid>0) AS a GROUP BY a.areaid ) AS orderArea LEFT JOIN dbo.Area AS a3 ON orderArea.AreaId=a3.ID LEFT JOIN dbo.Area AS a2 ON a3.HeadID =a2.ID LEFT JOIN dbo.Area AS a1 ON a2.HeadID = a1.ID

相關文章
相關標籤/搜索