Results 1 to 1 of 1
  1. #1
    Join Date
    Jun 2017
    Posts
    1

    Unanswered: Trailing/Rolling X Month Average in Current Month Query

    New to the forum and just learning how to use both SQL & PostgreSQL. My apologies if this was answered previously.

    My data set, lets just call it "data", consists of monthly revenues by Location. I would like to query and display each location's revenue for the current month, but would like to add a column that calculates the average revenue over the past 3, 6, or 12 months. The results that I am l hoping to achieve is:

    location current_revenue three_month_revenue six_month_revenue twelve_month_revenue
    a 20.00 18.00 19.00 22.00
    b 40.00 36.00 37.00 44.00
    c 60.00 54.00 55.00 66.00

    The Where clause would state the current month and the other three fields would would subtract x months back.


    Spacing on my table example is not displaying correctly and am having difficulty attaching a .png
    Last edited by JValadez1983; 06-29-17 at 15:29.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •