SQL 同比环比增长率计算

SQL 同比环比增长率计算同比 SELECTDISTIN dateM B dateY B Total B Total B Total AVG B per OVER PARTITIONBYB dateM asprediction AVG B per OVER PARTITIONBYB dateM AS AvgPer MA 统计第三季度销售额并计算环比增长率 sql

同比:

SELECT DISTINCT
    B.dateM,B.dateY,B.Total,B.Total+B.Total*AVG( B.per ) OVER ( PARTITION BY B.dateM ) as predictionTotal
    ,    AVG( B.per ) OVER ( PARTITION BY B.dateM ) AS [AvgPer]
    ,MAX( B.per ) OVER ( PARTITION BY B.dateM ) AS [MaxPer]
    ,Min( B.per ) OVER ( PARTITION BY B.dateM ) AS [MinPer] from 
    (SELECT A.dateM,A.dateY
 ,A.[Total] - A.[PreviousTotal] as GrowthTotal,(A.[Total] - A.[PreviousTotal])/A.[PreviousTotal] as per,A.[Total]
,    A.[Month]
FROM 
(
select s.dateM,dateY,COUNT(*) OVER ( PARTITION BY s.dateM ) AS [Month],s.[Total]  AS [Total]
,     LAG( s.[Total] ) OVER ( PARTITION BY s.dateM ORDER BY s.dateY ) AS [PreviousTotal] 
        from (SELECT datepart(mm,[month]) as dateM, datepart(yyyy,[month]) as dateY,sum([Total]) Tot

今天的文章 SQL 同比环比增长率计算分享到此就结束了,感谢您的阅读。
编程小号
上一篇 2024-12-10 10:30
下一篇 2024-12-10 10:27

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/82783.html