sqlserver 计算同比增长
时间:2021-07-01 10:21:17
帮助过:115人阅读
***** 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
sqlserver 计算同比增长
标签:sel code 计算 upd eid weight eric color stat