【问题标题】:Getting the Rolling Average获得滚动平均值
【发布时间】:2014-12-01 12:01:41
【问题描述】:

我有一个显示在下拉框中的日期列表,我需要获取每个月的 12 个月滚动平均值。日期列表位于名为 date_end 的列中。

SELECT total_subs, cust_region, cust_phone, date_end
FROM table_customer
where date_end >=  date_end - '13 months'

date_end 保存为 Ansidate。

date_end    
2014-08-31
2014-07-31
2014-06-30
2014-05-30

当用户从结束日期下拉列表中选择一个值时,查询应返回该结束日期与结束日期减去 13 个月之间的所选值

【问题讨论】:

  • 您使用的是哪个 DBMS?后格雷斯?甲骨文?
  • 这 13 个月的工作。
  • 请编辑您的帖子以指明查询中提到的列的数据类型并包含一些示例数据。和 - 什么列的滚动平均值?谢谢。
  • 获取total_subs的滚动平均值,它是一个整数,按地区、电话号码和date_end分组

标签: sql ingres


【解决方案1】:

你能在 Ingres 中做这样的事情吗?如果没有,请原谅我。

SELECT total_subs, cust_region, cust_phone, date_end, (
    (select avg(total_subs)
     from table_customer tc2
     where tc2.date_end > tc.date_end - '12 months'
    ) as rolling_average
FROM table_customer tc
where date_end >=  date_end - '13 months'

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 2015-09-11
    • 2015-04-03
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2022-01-17
    相关资源
    最近更新 更多