Calculate the average over the last 12 months
HelloI 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
Tags: Database
Similar Questions
-
How to calculate the final 5 months of sysdate?
Education - TO_CHAR(SYSDATE,'YYYYMM')-1 SELECT FROM DUAL gives 201300. The desired output is 201212, 201211, 201210, 201209 201208.
SanjayTry this
select to_char(add_months(sysdate, -1), 'YYYYMM') from dual union select to_char(add_months(sysdate, -2), 'YYYYMM') from dual union select to_char(add_months(sysdate, -3), 'YYYYMM') from dual union select to_char(add_months(sysdate, -4), 'YYYYMM') from dual union select to_char(add_months(sysdate, -5), 'YYYYMM') from dual
-
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
-
REQ: script to calculate the number of months
Looking for a script that will calculate the number of months between 2 dates (to 2 decimal points)
or if there is a way to make a calculation of the number of months
for example: if I go to google and say 75 days - months, it returns a value of 2.46
That's what I'm looking for
If anyone can help?
with a calculation of date or number calculation?
I tried # days / 365 x 12 but there is no decimal places. right guard rounded up/down
As mentioned in a month, the days are not constant throughout the year and change formula 28-31 days. How are you calculating the decimal value of the month?
A year has 365 days, if she did then there would be no need for leap years and centuries jump.
Calculation of a variable with the result of a calculation method is set to decimal.
cDateFormat = "d-mmm-yyyy";
var cStartDate = "January 1, 2000;
var oStartDate = util.scand (cDateFormat, cStartDate);
oStartDate.setHours (0, 0, 0, 000);
var cEndDate = "January 15, 2000;
var oEndDate = util.scand (cDateFormat, cEndDate);
oEndDate.setHours (0, 0, 0, 000);
nDiff var = oEndDate.getTime () - oStartDate.getTime ();
Console.println ("end date:" + cEndDate);
Console.println ("start date:"+ cStartDate ");
Console.println ("difference in milliseconds:" + nDiff);
Console.println ("difference in seconds:" + nDiff/1000);
Console.println ("difference in minutes:" + nDiff / (1000 * 60));
Console.println ("difference in hours:" + nDiff / (1000 * 60 * 60));
Console.println ("difference in days:" + nDiff / (1000 * 60 * 60 * 24));
Console.println ("difference in weeks:" + nDiff / (1000 * 60 * 60 * 24 * 7));
Console.println ("difference over the years:" + nDiff / (1000 * 60 * 60 * 24 * 365.2524));
Console.println ("difference in months:" + nDiff / ((1000 * 60 * 60 * 24 * 365.2524) / 12)); 12 months in a year;End date: January 15, 2000
Start date: January 1, 2000
Difference in milliseconds: 1209600000
Difference in seconds: 1209600
Difference in minutes: 20160
Difference in hours: 336
Difference in days: 14
Difference of weeks: 2
Difference in years: 0.0383296591617194
Difference in months: 0.45995590994063273Several turncate the decimal values scirpts because keeping them may not meet the need of specific calculation. You know that there are methods to roud until the next iniger, round.5 to the top and turnacate to the lower intiger.
According to the date of departure, the values may be different:
For a start date of February 1, 2000, 75 days would be 1,810 months but for a start date of 1 February 2001 75 days becomes 1,838 since the number of days of changes of February 29 to 28 and the number of days for the month of fractions varies from 26 to 27.
-
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
-
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.
~~~~~~~~~~~~~~~~~~~~~~~
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
-
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?
Maybe check the related threads and see why others also had problems with this update:
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 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!
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. "
-
Calculate the previous three months
I want to calculate the past 3 months on the basis of sysdate in 3 separate columns. I get the previous month by executing the following SQL statement:
The current month is July, then how can I get 05, 04 as output.select EXTRACT(MONTH FROM TRUNC(SYSDATE,'MONTH')-1)mn1 from dual
YogeshHello
Just remove TRUNC...
select EXTRACT(MONTH FROM (SYSDATE))-1 mn1,EXTRACT(MONTH FROM (SYSDATE))-2 mn2,EXTRACT(MONTH FROM (SYSDATE))-3 mn3 from dual;
AJ
-
BI answers; Filters registered; Over these last 12 months
I have just started preparation obiee. in the creation of interactive dashboards and using oracle BI answers module (http://st-curriculum.oracle.com/obe/fmw/bi/biee/r1013/saw/saw.html).
the tutorial says "* add a filter registered in the query to limit the data of the last douzemois (based on the HS data, this will cover from January to December 2001).» Under filters in the left pane, expand the SH file and click on the most recent 12 months *. "but I couldn't find any saved filter named over these last 12 months. I could not continue further in the tutorial, kindly let me know how to create this filter.Specify where you got stuck.
(1) Firstly, it must look at the bottom of the left pane and find "filters". Ok?
(2) click on it to reveal everything beneath it. Saved filters are saved under the domain, so you should find a section called "SH". Ok?
3) click on 'SH '. This topic, you should find the saved filter you are looking for. Ok?
Have you found?
Maybe you are looking for
-
Defective Portege R700M - BIOS & HDD password reset
Hello My Portege R700M stopped working after I hit the top. Service center had rejected citing 'Mother, damaged card', the laptop has been installed for the protection of the BIOS for the HARD drive password. Even if the hard drive is intact, I am no
-
Satellite P100-221: nVidia driver from Toshiba site does not work
HEY! PLEASE PUT THE RIGHT VIDEO FOR SATELLITE P100-221 DRIVER!THIS DRIVER IS NOT FOR GO 7900 GS GRAFIC CARD!
-
Has been installed 4 times and did not have twiced; keeps trying to installed itself over and over
-
December 29 update package includes the 3 items, how can I download one?
The December 29 update package includes a 1.5 MB for XP security update. I want that. The update also includes an update 25 MB 'Microsoft Office Access Runtime and Data Connectivity 2007 Service Pack 3 (SP3)... '. I DON'T WANT THAT AND a 275,7 MB upd
-
HOW TO LOAD DIMENSIONS / MEMBERS IN ESSBASE ASO REQUEST
HelloWe are running Oracle EPM 11.1.2.4 and created with success the planning application help EPMA workspace, it is necessary to create a reporting application. We have created a new application of ePMA workspace as essbase ASO and have dimensions o