SELECT a.[品牌], a.[门店], b.[日期], b.[实际营收], c.[计划营收] FROM ( SELECT t1.BrandName 品牌, t1.HotelName 门店, t1.ShopID 门店id, t1.HotelID 饭店id FROM [dbo].[DIM_POS_Shop] t1 WHERE t1.HotelName NOT IN ('', '测试门店') ) a LEFT JOIN ( SELECT t2.ShopID 门店ID, t2.BillDate 日期, SUM (t2.Amount) 实际营收 FROM [dbo].[FACT_POS_Bill] t2 WHERE t2.OrderStatus = '40' GROUP BY t2.ShopID, t2.BillDate ) b ON a.[门店id] = b.[门店ID] LEFT JOIN( SELECT t3.ShopID 门店id, t3.TargetDate 日期, SUM (t3.[Value]) 计划营收 FROM [dbo].[FACT_Target_Day] t3 WHERE t3.Items = '营收(万元)' GROUP BY t3.ShopID, t3.TargetDate )c on c.门店id=a.饭店id and b.[日期]=c.[日期] where ${if(type='date'," and CONVERT(varchar(100),b.[日期],20) >= '" + 开始日期 + "' and CONVERT(varchar(100),b.[日期],20)<='" + 结束日期 + "'", "")} |