今天,我重新检查了一个困扰已久的问题,在经过仔细的考虑,算是找到了一个比较合理的解决办法。
问题是这样的,表StoreProductSales记录一系列的商场以及它们每天的营业额。商场与商场之间有从属关系,记录在Store_WithAcestor表里。当用户查询某个商场的对某个产品的销售额时,除了返回自己的营业额,还需要包含所有子商场的营业额。
示例结构和数据如下:
StoreProductSales
(
DayId int,
StoreId nvarchar(8),
ProductId nvarchar(8),
Sales int
)
Insert into StoreProductSales values(1,'BJ','Cloth',100)
Insert into StoreProductSales values(1,'BJ','