Average of the last 12 months

Hello

I have a sum of the column. I need to find the avg of it for the last 12 months, excluding the current month.
I have a request to find .but it is the addition of current month also with her.

AVG (Sum (amount)) (IN ACCOUNT_MONTH_NO ORDER

Rolling_avg of LINES BETWEEN 12 SUITE BEFORE AND 0).

Please help me write a query as I am a naïve user to oracle.

As...

SQL> select * from test;

ACCOUNT_NU ACCOUNT_MONTH_NO     AMOUNT
---------- ---------------- ----------
ACC1                      1        100
ACC1                      2        200
ACC1                      3        300
ACC1                      4        400
ACC1                      5        500
ACC1                      6        600
ACC1                      7        700
ACC1                      8        800
ACC1                      9        900
ACC1                     10       1000
ACC1                     11       1100
ACC1                     12       1200

12 rows selected.

SQL> select account_month_no,amount,
  2     avg(amount) over(order by account_month_no rows
  3            between 12 preceding and 1 preceding) avg
  4  from test
  5  where ACCOUNT_NUMBER  = 'ACC1';

ACCOUNT_MONTH_NO     AMOUNT        AVG
---------------- ---------- ----------
               1        100
               2        200        100
               3        300        150
               4        400        200
               5        500        250
               6        600        300
               7        700        350
               8        800        400
               9        900        450
              10       1000        500
              11       1100        550
              12       1200        600

12 rows selected.

View sample data and expected results, so that we can help you better

Tags: Database

Similar Questions

  • Calculate the average over the last 12 months

    Hello

    I am trying to calculate the average value per customer and per month from and including the month and 12 months back

    for example: 1 January 12 = average (agreed_rate) & (process_rate) average from February 1st, 11 'and 1st January 12'.
    February 1, 12 = average (agreed_rate) & (process_rate) average of 1 March 11 'and 1 February 12'
    March 1, 12 = average (agreed_rate) & (process_rate) average of 1 April 11 'and 1st March 12' etc.

    create table (test)
    cust_num varchar2 (5).
    month, date, time,
    number of agreed_rate
    number of process_rate);

    insert into test values ("A001", January 1, 11 ', 87, 65);
    insert into test values ("A001", February 1, 11 ', 56, 62);
    insert into test values ("A001", March 1, 11 ', 76, 88);
    insert into test values ("A001", April 1, 11 ', 45, 69);
    insert into test values ("A001", may 1, 11 ', 99, 65);
    insert into test values ("A001", June 1, 11 ', 98, 43);
    insert into test values ("A001", July 1, 11 ', 87, 70);
    insert into test values ("A001", August 1, 11 ', 43, 99);
    insert into test values (' A001', ' 01 - SEVEN.-11', 62, 32 ');
    insert into test values ("A001", October 1, 11 ' 89, 44);
    insert into test values ("A001", November 1, 11 ', 34, 65);
    insert into test values ("A001", December 1, 11 ', 87, 87);
    insert into test values ("A002", January 1, 12 ', 33, 65 ");
    insert into test values ("A002", February 1, 12 ', 56, 23 ");
    insert into test values ("A002', March 1, 12 ', 76, 46 '');
    insert into test values ("A002', April 1, 12 ', 67, 69");
    insert into test values ("A002', may 1, 12 ', 99, 33");
    insert into test values ("A002', June 1, 12 ' 89, 21");
    insert into test values ("A002', July 1, 12 ', 87, p. 77");
    insert into test values ("A002', August 1, 12 ', 69, 99");
    insert into test values ("A002', '' 01-SEP-12, 89, 32");
    insert into test values ("A002', October 1, 12 ', 43, 20");
    insert into test values ("A002', November 1, 12 ', 34, 56");
    insert into test values ("A002', December 1, 12 ', 77, 78");

    JAN-12 e.g. agreed_rate average = (33 + 87 + 34 + 89 + 62 + 43 + 87 + 98 + 99 + 45 + 76 + 56) / 12
    FEB-12 average agreed_rate = (56 + 33 + 87 + 34 + 89 + 62 + 43 + 87 + 98 + 99 + 45 + 76) / 12

    The results should be displayed per month (like the example above) and cust_num.

    Can anyone help?

    Thank you

    You must go to the current line, that is included as twelfths a form 11 months.
    If you round the result is 67,42 67,41 rather than. This is the result on all the cust_num.
    If you want to the result for each customer comment just the partiton of clause.

    SELECT      cust_num, month, agreed_rate
    ,      round (sum (agreed_rate) OVER ( --PARTITION BY  cust_num
                                    ORDER BY month
                       RANGE
                       INTERVAL '11' month
                       preceding
                       ) / 12,2) AS avg_agreed_rate
    FROM       test
    ORDER BY  month
    

    Partition on cust_num

    SELECT      cust_num, month, agreed_rate
    ,      round (sum (agreed_rate) OVER ( PARTITION BY  cust_num
                                    ORDER BY month
                       RANGE
                       INTERVAL '11' month
                       preceding
                       ) / 12,2) AS avg_agreed_rate
    FROM       test
    ORDER BY  month
    

    Published by: chris227 on 01.02.2013 01:51
    the corrected table name

    Published by: chris227 on 01.02.2013 01:52

  • Malicious software removal tool update problems the last few months. Suspended for a very long time. Vista Home Premium 32 bit SP2

    Hello

    The last 3 months when the download and installation of my updates for Windows Vista, it gets stuck for hours on the malicious software removal tool. I have to cancel it. Restart the computer and reinstall. Then he moved very well and quickly according to historical updates. Last month, it was really difficult to cancell it well. He finally got through it. Here is a little history on my machine. I'm very very well with this computer. Each week, I do disk Cleanup, then defrag with diskeeper, virus scan with Microsoft Security Essentials. And every six months, I run a very large disk check and I said to correct errors and try to fix bad sectors. More than 3 years, I only had 2 minor bluescreens. I always make sure I have all my products Microsoft put updated. When I first got this computer I had a guy I.T. (a neighbor) out of the box and clean all the useless garbage out of it and it partitioned the hard drive. More than 3 years, he managed as a champion. Always very fast and all.

    I hope that I'm not the only person having problems with this. Just start with the month of June, then July, then August.

    P.S. I have 2 laptops running XP sp3, one is 9 years old and the other is 11 years old, he had 2000 top PRO, but I just put XP sp3 on it last month. They run too much like fields. I take good care of my computers with a little help from my friend IT. They have the same programs as this one and I do the same things to them, but they do not have this same problem with the release of the MSRT tool. Which leads me to think that it is specific to Vista only, I have a Windows 7 computer yet, so I can't speak for seven.

    Any suggestions or ideas? We are scratching our heads on this one.

    Thank you in advance for your time and help

    Tim Kerr

    Your misguided use of registry cleaners could have caused this behavior! If you ever think that your registry database must be cleaned, repaired, amplified, to the point, cured, twisted, fixed or optimized (it isn't), read http://aumha.net/viewtopic.php?t=28099 and draw your own conclusions.

    See also http://blogs.technet.com/markrussinovich/archive/2005/10/02/registry-junk-a-windows-fact-of-life.aspx

    ~~~~~~~~~~~~~~~~~~~~~~~

    Your use of Revo Uninstaller and the foregoing notwithstanding, applications, (Norton and McAfee) are known to not uninstall (or upgraded) themselves.

    1. download the Norton Removal Tool, save it to your desktop: ftp://ftp.symantec.com/public/english_us_canada/removal_tools/Norton_Removal_Tool.exe

    2. close all open applications (that is, anything with an icon on the taskbar).

    3. click right on the file saved in #1 above, and then select run as administrator to run the utility. DO TAP not your keyboard until the race ends, then restart.

    4. open IE (only) to http://support.microsoft.com/kb/971058 & run it in DEFAULT and modes difficulty then AGGRESSIVE. [1]

    5. restart & test (i.e. the or shortly after seven 14-10 when the next MRT is scheduled to be released).

    ~~~~~~~~~~~~~~~~~~~~~~~~
    [1] full Disclosure: the difficulty operating in AGGRESSIVE mode will remove your update history but not the list of installed updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • -Error code 646 - repeated the failures (now for the last two months) to install updates Windows 7 S/W, possibly after installation of Office 2010?

    For the last two months - easrly November, when stopped down, I saw 10 message updates are being installed. This follow-up installation of Office 2010 (download from Web site), who bought Office 2007 earlier this year, and by choosing to take the free update promised for 2010.

    On the control, I find that whenever all ten updates failed to install (error code 646)

    Concered updates are KB2202188; KB982726; KB2289161; KB2289078; KB2413186;  for Office 2010

    and KB2345000 - Word 20120.

    KB2409055 - 2010 Editor;

    KB2289116 - Social connector;

    KB2431831 - knitting 9;

    KB2433299 A Note;

    Any thoughts there?

    Steve L

    A KB was created for 646 error code that appears during the installation of the updates of Microsoft Office. The KB includes an automatedMicrosoft fix 50461 that corrects the problem. Look at the following KB:http://support.microsoft.com/kb/2258121http://snipurl.com/164ypp>

    Suggest you download and save the fix it.

    Then close all open programs and browsers before running MSFix it 50461.msi.

  • I could not install the update KB2686509 for Widows XP Pro, for the last 6 months. WHY?

    I could not install the update KB2686509 for Widows XP Pro, for the last 6 months. WHY?

    Maybe check the related threads and see why others also had problems with this update:

    http://answers.Microsoft.com/en-us/search/search?searchterm=KB2686509&CurrentScope.ForumName=&CurrentScope.filter=&askingquestion=false

    especially this thread: http://answers.microsoft.com/en-us/windows/forum/windows_xp-windows_update/kb2686509-repeatedly-fails-with-error-code/0deeacb6-115c-419d-ac37-03ff8927b79c

    That should answer your question about why you have a problem installing the update.

  • How to view the last 12 months of data in dashboards OBIEE 11 g?

    I need to create a report to show a metric for the last 12 months... How can I do that exactly?

    I know I should use the TimeStampAdd() function, but it does not somehow for... Please list me the details step by step if possible (filters, syntax, PivotTable).

    I'm basically pulling in a column of calendar month (e.g. YYYY / MM - 2014 / 01) and the quantity ordered (column of fact).

    Thank you

    Pat

    Hello

    Thanks for the reply... I think I got it however.

    Done via a pivot table... and he showed me the previous 12 months.

  • I would like to get the list of all devices on which my creative cloud has been activated for the last six months or a year

    I would like to get the list of all devices on which my creative cloud has been activated for the last six months or a year

    I do not think that information... Adobe titles represent the only link I know following your accounts, but not where the programs are installed

    https://Accounts.adobe.com/ , then click on Plans & products above to find a list of your programs and your serial numbers

  • PowerCLI to find the host added in vcenter in the last 12 months

    Hello

    Can we use Powercli to find the host added in vcenter in the last 12 months

    Thank you

    The Get-VIEvent cmdlet and look for the HostAddedEvent.

    Get-VIEvent-beginning (Get-Date). AddYears(-1) - MaxSamples ([int]: MaxValue) |

    Where {$_-is [VMware.Vim.HostAddedEvent]}

    You can also use my Get-VIEventPlus function.

    Get-VIEventPlus-beginning (Get-Date). AddYears(-1) - EventType HostAddedEvent

  • I get a message saying "drive does not have the ability to access this service and I just paid for 12 months (FOR THE SECOND TIME) in the last two months!

    I get a message saying "drive does not have the ability to access this service and I just paid for 12 months (FOR THE SECOND TIME) in the last two months!

    Hi phillipt84805120,

    Make sure that you have the latest Adobe Acrobat Reader DC (Adobe Acrobat Reader DC install for all versions) installed on your computer to use the services of export to PDF as the older version of Reader support any more.

    Alternatively, you can use services online at https://cloud.acrobat.com/exportpdf

    Let me know if you are still having a problem.

    Kind regards

    Nicos

  • Is why Adobe acting like I didn't pay the last 6 months?

    Today, for the first time in 6 months that adobe allow me to use it, I realize that my subscription might have worn out now, but the way he wants me to pay for more is saying that my trial has expired? I'm sorry if this is a lot of nothing I'm worried, but it seems that I had to pay to run a demo version of the software the last six months now... The software has been excellent all this while and I had all intend to renew my prescription, but now I'm second guessing myself a lot of time...

    Your subscription to cloud shows correctly on your account page?

    https://www.adobe.com/account.html for subscriptions on your page from Adobe

    If Yes

    Some general information for a subscription of cloud

    Sign out of your account of cloud... Restart your computer... Connect to your paid account of cloud

    -Connect using http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html

    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    If no

    This is an open forum, Adobe support... you need Adobe personnel to help

    Adobe contact information - http://helpx.adobe.com/contact.html

    -Select your product and what you need help with

    -Click on the blue box "still need help? Contact us. "

  • Update 3.5 LR has same version as the last updated months ago (?)

    LR 3.5 update has same version as the last updated months ago. Camara Raw has been V6.6 PShop but rest V6.5 in LR. What is the scheduled update?

    Thanks Jake! Your image showing v3.6 LR w / ACR 6.6 made me try all over again my WIND7 LR v3.6 Update v3.5. This time I did it! However, it was not the 'normal' procedure Usually when I throw my LR and there was an announcement of update to Adobe, I simply click on the button that says to proceed with the update. When I do that for this update it took me to a dialogue that had me download LR v 3.5 again. Not good! So this time I had to search for LR v3.6 under recent Adobe updates lines. He was there! And it worked.

    -paul

  • Function numbers for dynamically on average over the last 30 cells

    I am a trader and I have several months of data. I currently have a percentage of the sum of all the victories and defeats by currency pair. I want to create a function that retrieves the last 30 cells of data and creates a percentage I can compare it to the percentage of total victory.

    The cells are empty, unless I have add data in either to the upper or lower row. 1 win and - 1 are losses. 0 means not configured.

    Here's a full month with 20 data cells (cells max per month are 22) of trading days:

    This is the current month:

    I have 16 months of data with percentages of victory for all my data. As you see, I also have winning monthly winning percentages easily in the examples above (with a small division). I really, really want to compile data from the last 30 cells with data to create a winning percentage. It would be necessary to sometimes include 3 different lines of different months of data to create 30 cells with a number inside.

    A friend used the COUNTIF command but I do not have it works for me.

    If there is a different website to request this detail of the question please share that too.

    Thanks in advance,

    B

    Hi Braddon,

    It would be a pretty easy task if the data to be summed up in two columns from a single table and had no gaps, but that doesn't seem to be the case.

    Screenshots of two isolated sets of cells containing two rows (railway of) the data to be summarized, but give no indication where these data will be found in the document does not provide sufficient information to start to find a solution.

    Where are the data stored? You say "data for each month." "Every month" is recorded on another table?... on a pair of rows of the same table different?

    In the image (very vague) I, the factors of complications will gather data from a subset of continually changing several tables on multiple sheets and which specific cell contains the 30 most recent reference and is the one to start the harvest.

    While a few details and clarifications.

    Kind regards

    Barry

  • after update, the Favorites have disappeared. There is no automatic backup in the last 2 months. under the restoration, it gives me the possibility to restore until today.

    all of a sudden I have no Favorites.

    I read to all bookmarks, clikc backup and restore, restore and it will list the last 10 backups. the only listed backup is starting today, and no bookmarks are added when I restore

    I also saw to look on the desk in the old firefox files... most recent automatic backup was 2 months ago... it's too old

    I can't find the latest bookmarks files

    If you haven't tried stopping and restarting Windows because this problem occurred, I would suggest trying it. Some users have reported a problem after the updates of Windows where they see only partial information in Firefox, perhaps because of a problem of privileges.

    After that, if the problem persists, I'll ask you to verify a parallel settings folder. You can open the settings file (AKA Firefox profile) current Firefox help

    • button "3-bar" menu > "?" button > troubleshooting information
    • (menu bar) Help > troubleshooting information
    • type or paste everything: in the address bar and press Enter

    In the first table of the page, click on the view file"" button. This should launch a new window that lists the various files and folders in Windows Explorer.

    Make a note of the name of the current folder in the Windows Explorer address bar, and then click the 'profiles' word that appears before him to navigate a level and see if you find other profile folders here. If you check the inside, a folder bookmarkbackups in other profiles appear to be current?

    IMPORTANT: Do not use Windows System Restore feature — which can cause loss permanent data.

  • How do the average of the last 5 values of a column as new values automatically entered?

    If the issue is not clear for you, here's a site I found that teaches you how do it on excel. ml https://www.extendoffice.com/documents/Excel/2533-Excel-average-last-5-values.HT    I can't find the corresponding method on the good numbers. Thank you for your response in advance :-)

    Hi Z_J,

    This number approach pulls the last 5 (low) values of table 1 in another table where the average can be calculated.

    Step 1. Add line numbers in column A of table 1. This gives a way for table 1-1 to extract the last 5 values.

    Formula in A2 (and fill down

    = ROW()

    Step 2.

    In table 1-1, the formula in A6 estimated the maximum line in table 1

    = MAX (Table 1::A)

    The formula in A5 (and filling up)

    = A6−1

    Formula in B2 of table 1-1 (and fill down) using VLOOKUP to find a match for each line number in table 1-1 and get the value out of this line in table 1.

    = VLOOKUP(A2,Table 1::A:B,2,FALSE)

    Step 3.

    Now add another row (and insert a new value) to the lower part of table 1

    Lines 3 to 7 are now drawn.

    Ranger by hiding some columns

    Kind regards

    Ian.

  • Why all the BSOD? More in the last 10 days than the last 10 months

    All of a sudden in the last 10 days, my PC has been constantly stop, a few automatic reboots [I know because Google Chrome, Opera & Internet Explorer all ask what I want to open the pages who suddenly disappeared]. Others showing the BSOD of different color...

    Sometimes I got BSOD too, although on these occasions, it was not the old blue screen dark with a myriad of writing, instead a lighter blue screen telling me to stop, the evidence gathered [to up to 100% and then auto shut off and reboot]' the last 3 times there have been various error messages invited me to do a search on the internet for the answer...

    IRQL_NOT_LESS_OR_EQUAL

    DRIVER_POWER_STATE_FAILURE

    KERNEL_DATA_INPAGE_ERROR

    I did a bit of googling, found at Microsoft support group where others have been invited to copy, the minidump zip files and upload to skydrive; what I've done; the zipped file is available for reading... but do not have done this before. I'm not sure of the next step... I tried to simply enter answers.microsoft.com in the municipality filed, but it was not acceptable...

    If I had to guess, in the previous six months before the current problems, I doubt that there are 2 episodes of BSOD stop.

    I am running windows 8.1 completely up to date and it's really p * sing me OFF... others may say their system starts up quickly, and I confess that I have 3 or 4 drives external storage, and I use Acronis as a safeguard measure after the last time I had to reload Windows [due to a failed update]... but after BSOD today... I timed it the beginning upward and it took 1 min 45 sec as soon as the start screen first showed... when the blocked password login screen appeared... so I want this issue fixed! PLEASE...

    Chris

    There are 3 different causes, but according to me, there is an underlying problem.  Please run the Driver Verifier to find which driver he is

    These accidents were related to the corruption of memory (probably caused by a driver).

    Run these two tests to check your memory and find which driver is causing the problem.  Launch auditor.  You don't need to run memtest again unless the auditor is not the cause, or you want to.

    If you are overclocking anything reset by default before running these tests.
    In other words STOP! If you don't know what it means that you're probably not  


    1-Driver Verifier (for full instructions, see our wiki here)

    2-Memtest. (You can learn more about running memtest here)

Maybe you are looking for