110,533
社区成员
发帖
与我相关
我的任务
分享
create table #car
(years int, --年份
months int, --月份
num int, --销售数量
area nvarchar(28) --地域
)
insert into #car
select 2008,1,30,'华中' union all select 2008,2,20,'华南' union all select 2008,12,40,'华北' union all
select 2009,1,15,'华中' union all select 2009,2,50,'华南' union all select 2009,12,70,'华北' union all
select 2010,1,130,'华中' union all select 2010,2,40,'华南' union all select 2010,12,100,'华北'
--写出 years months area num 同比, 环比,累计销量,累计同比,累计环比
--解释: 同比 = (当年当月销量 -去年当月销量)/去年当月销量
-- 环比 = (当年当月销量 -上月销量) / 上月销量
-- 累计销量 = 当年累计销量之和
select area,years,months,num from #car