博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

order订单表,orderprduct订单商品表,area地区表

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

posted on 2014-05-07 10:05    阅读(369)  评论(0编辑  收藏  举报