/****** Script for SelectTopNRows command from SSMS ******/ SELECT [fdSequenceID] ,[fdInnerTime] ,[fdTime] ,[fdData] ,[fdState] ,[fdUpdateTime] ,[fdCreateTime] FROM [NewDBTest].[dbo].[tbDataMonthHG] WITH f AS ( SELECT ROW_NUMBER()OVER( partition by fdSequenceID ORDER BY fdTime) AS id, * FROM [NewDBTest].[dbo].[tbDataMonthHG] ) select t.*, fdRate=(cast(cast(100*((t.fdData/NULLif(d.fdData,0))-1) as numeric(25,10)) as varchar(50))+‘%‘ ) --小数变百分数 from f t left join f d on t.fdInnerTime = DateAdd(year,1,d.fdInnerTime) and t.fdSequenceID = d.fdSequenceID --同比增长 order by fdSequenceID,id asc
时间: 2024-10-13 04:51:14