在SQL中从一段时间内的累计总数中查找销售增长

时间:2020-06-11 16:53:46

标签: sql

enter image description here

Need help with Creating the Sales Growth column

SELECT CUST_ID,CONTACTS 
        Sum("CONTACTS") Over (PARTITION by "CUST_ID" Order By "end_Period"  ROWS UNBOUNDED PRECEDING) as RunningContacts,
        "SALES",
        Sum("SALES") Over (PARTITION by  "CUST_ID" Order By "end_Period"  ROWS UNBOUNDED PRECEDING) as RunningSales,
    end_Period
FROM    Table2

我目前已经在excel公式中创建了“跑步增长”列,该栏是(新跑步销售-之前跑步销售)/以前跑步销售。

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

SQL派生表可以保存一个查询,以按期间汇总销售额,您可以对其进行联接以将每个期间与上一个期间进行比较。

答案 1 :(得分:0)

您在寻找这个吗?

select t.*,
       RunningSales / (Running - Sales) - 1
from (< your query here > ) x