目前数据量比较大,所以觉得这个方案可以尝试,但是我不知道怎么改sql 目前的sql: SELECT a.BillDate 日期, YEAR (a.BillDate) 年份, MONTH (a.BillDate) 月份, DAY (a.BillDate) 日, a.ShopID 门店ID, b.BrandName 品牌, b.HotelName 门店, SUM (a.Amount) 实际营收, c.[Value] 计划营收 FROM [dbo].[DIM_POS_Shop] b LEFT JOIN [dbo].[FACT_POS_Bill] a ON a.ShopID = b.ShopID LEFT JOIN [dbo].[FACT_Target_Day] c ON c.ShopID = b.HotelID where c.Items = '营收(万元)' ${if(type='date'," and CONVERT(varchar(100),a.BillDate,20) >= '" + 开始日期 + "' and CONVERT(varchar(100),a.BillDate,20)<='" + 结束日期 + "'", "")} ${if(type='month', " and cast(month(CONVERT(varchar(100),a.BillDate,20)) as int) = "+ 月 + " and year(CONVERT(varchar(100),a.BillDate,20)) = '" + 年+"'", "")} ${if(type='year', " and year(CONVERT(varchar(100),a.BillDate,20)) = '" + 年+"'", "")} ${if(len(品牌)==0,"","and b.BrandName in ('"+品牌+"')")} ${if(len(门店)==0,"","and b.HotelName in ('"+门店+"')")} GROUP BY a.ShopID, a.BillDate, b.BrandName, b.HotelName, c.[Value] 图一是按日维度的效果,是没有问题的: 图二我选择了按月维度,但是这个内容里面还是按天展示,我想要按月展示数据,数据汇总起来: 图三也是想要以年汇总: |