Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:14:43+00:00 2026-06-14T23:14:43+00:00

I am trying to get a rolling 12 month total from a set of

  • 0

I am trying to get a rolling 12 month total from a set of data that provides the minutes for a given month and year. In many cases, I will not have a a record for a month. Is there a way to display the missing months with a zero (0) for the value and then roll it up or not display them but have the query acknowledge this as part of the 12 month range. The below query is what I was trying to use but it just grabs the prior records and does not take into account missing months. The query below does not seems to be off a little with some of the totals. Any assistance would be greatly appreciated.

    Select year
         , month
         , SUM(NVL(minutes, 0)) OVER (order by year,month rows between 11 preceding and current row) as total_minutes
    from
    (
    Select *  
    from test_table
    Order by year, month
    )
    Order by year desc , month desc

Here is the sql to create the test table and data.

    drop table test_table;
    create table test_table (
      month    number(2),
      year     number(4),
      minutes  number(4,2)
    );

    insert into test_table values ( 1, 2012, 3 );
    insert into test_table values ( 2, 2012, 3 );
    insert into test_table values ( 3, 2012, 3 );
    insert into test_table values ( 4, 2012, 4 );
    insert into test_table values ( 5, 2012, 5 );
    insert into test_table values ( 7, 2012, 5 );
    insert into test_table values ( 8, 2012, 5 );
    insert into test_table values ( 9, 2012, 5 );
    insert into test_table values (10, 2012, 4 );
    insert into test_table values (11, 2012, 3 );
    insert into test_table values (12, 2012, 3 );
    insert into test_table values ( 1, 2011, 3 );
    insert into test_table values ( 2, 2011, 3 );
    insert into test_table values ( 5, 2011, 5 );
    insert into test_table values ( 6, 2011, 5 );
    insert into test_table values ( 7, 2011, 5 );
    insert into test_table values ( 8, 2011, 5 );
    insert into test_table values ( 9, 2011, 5 );
    insert into test_table values (10, 2011, 4 );
    insert into test_table values (11, 2011, 3 );
    insert into test_table values (12, 2011, 3 );
    insert into test_table values ( 1, 2010, 3 );
    insert into test_table values ( 2, 2010, 3 );
    insert into test_table values ( 3, 2010, 3 );
    insert into test_table values ( 4, 2010, 4 );
    insert into test_table values ( 5, 2010, 4 );
    insert into test_table values ( 6, 2010, 5 );
    insert into test_table values ( 7, 2010, 5 );
    insert into test_table values (10, 2010, 4 );
    insert into test_table values (11, 2010, 4 );
    insert into test_table values (12, 2010, 3 );

    COMMIT;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:14:45+00:00Added an answer on June 14, 2026 at 11:14 pm

    I did use the outer join but that didn’t give me the rolling 12 month range that I needed. I had to use the Windowing Clause to get the range and numbers to come out right.

        with m_num as(
          select level as mn
           from dual
         connect by level <= 12
        )
        select year
             , mn
             , minutes
             , sum(minutes) over(order by year,mn rows between 11 preceding and current row) rt
        from ( select tt.Year
                    , mn.mn
                    , nvl(tt.minutes, 0)  minutes
                from test_table tt
                partition by (tt.year)
                right outer join m_num mn
                  on (tt.month = mn.mn)
             )
        order by year desc, mn desc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am investigating trying to get my team at work to move from CVS
This is my first WPF project. I'm trying to get a rolling credits effect
We're trying to get some usage metrics on a VB6 application that we are
I'm trying to get NSClipView to either draw a clear background (set the color
I'm trying to create a simple session cache that allows me to set a
trying to get all of the log statements from class GetThatDataFilters to go to
So i am trying get 2 div-containers which both should contain centered text (Both
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.