How to calculate cumulative data
HelloI need output like this.
Percent frequency percent Cumulative Cumulative frequency
4468 0.91 0.91 4468
21092 4.31 25560 5.23
57818 11.82 83378 17.05
I use Oracle 9i.
My data of output like that and I need to write the query for 3 columns (frequency, percent, the cumulative frequency and cumulative percentage)
1: the formula for the frequency column data is the sum of (dd + cc + mc_cc_mc).
1: the formula for the percentage column data is (frequency/amount of cumulative frequency) * 100
2: is the formula for the cumulative frequency column data (data of the cumulative frequency column of)
3: is the formula for the cumulative percentage column data (data for the cumulative percentage column of)
What should be the analytical function and how to write the query. Please find the sample of data and table script.
CREATE TABLE all_lony)
CampNO varchar2 (20).
DD INTEGER,
CC INTEGER,
MC, INTEGER,
cc_mc INTEGER
);
insert into all_lony (campno, dd, cc, mc, cc_mc)
values (36,156,1320,445,2547);
insert into all_lony (campno, dd, cc, mc, cc_mc)
values (40,233,19711,263,885);
=============
Please find my query below
SELECT campno
|| ','
|| DM
|| ','
|| CC
|| ','
|| MC
|| ','
|| cc_mc
|| ','
|| frequency
|| ','
|| by
||','
|| cumulative_fr
||','
|| AMOUNT (per) OVER (ORDER BY by LINES UNBOUNDED PRECEDING)
FROM (SELECT campno q3.campno, q3.dm, q3.cc, q3.mc, q3.cc_mc,
Q3. Frequency, q3.cumulative_fr,
(q3. Frequency / SUM (q3.cumulative_fr)) * 100
(Q2.campno SELECT campno, SUM (q2.dm) dm, SUM (q2.cc) cc,)
SUM (q2.mc) mc, SUM (q2.cc_mc) cc_mc,
(SUM (NVL (q2.dm, 0)))
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc, 0)
)
) the frequency,.
SUM (SUM (NVL (q2.dm, 0)))
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc, 0)
)
) ON (ORDER OF the SOMME (NVL (q2.dm, 0)))
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc, 0)
() THE UNBOUNDED PRECEDING LINES)
cumulative_fr
of all_lony
Q2 Q1)
GROUP BY q3.campno) q3
GROUP BY campno, dm, cc, mc, cc_mc, frequency, cumulative_fr)
Just check the query and let me know
Hello
Everything is given.
Each column formula is given...thriugh this we can get all the required result.
The query is not working properly thats the issue and thats why i posted this whole senario.
I don't think that everything is given. You gave:
select * from all_lony
CAMPNO DD CC MC CC_MC
36 156 1320 445 2547
40 233 19711 263 885
And you want to:
Frequency Percent Cumulative Frequency Cumulative percent
4468 0.91 4468 0.91
21092 4.31 25560 5.23
57818 11.82 83378 17.05
First of all, you want 3 rows where we start with 2. I don't see anyway to generate the 3rd rank on 2 data.
With the following simple query, I get the frequency and the Cumulative_freqency.
select
campno
,dd + cc + mc + cc_mc Frequency
,sum(dd + cc + mc + cc_mc ) over (order by campno) Cumulative_freqency
from
all_lony
CAMPNO FREQUENCY CUMULATIVE_FREQENCY
-------------------- --------- -------------------
36 4468 4468
40 21092 25560
As you can see that your formula for the frequency is not give the result that you want.
1: the formula for the frequency column data is the sum of (dd + cc + mc_cc_mc).
This should be:
1: the formula for the frequency column data is dd + cc + mc_cc_mc.
Now the percentage formula
1: the formula for the percentage column data is (frequency/amount of cumulative frequency) * 100
I think you mean
1: the formula for the percentage column data is (frequency / cumulative frequency) * 100
But this does not 0.91 or 4.31 as in your result set.
Then please explain in a simple furmula with the sample values you have given the way in which we can calculate the percentage column.
The cumulative percentage column follows out of the percentage column.
Then explain how to get the 3rd rank.
Kind regards
Peter
Tags: Database
Similar Questions
-
How to calculate stock data aging
How to calculate inventory aging of data:
On top of the data, balance the stock of data is produced * 525 * by subtracting CRD_QTY from DRB_QTY. Now his result of aging from 18 September 2011 "should be like this:"_*PRS_DTE*_ _*PRD_COD*_ _*PRD_TYP*_ _*DRB_QTY*_ _*CRD_QTY*_ 15/07/2011 2012001234 1 100 0 15/08/2011 2012001234 1 200 0 16/08/2011 2012001234 1 0 50 15/06/2011 2012001234 1 125 0 15/09/2010 2012001234 1 150 0
Can I get this SQL result? I do not want to write cursors and loops to get the above given the result even if it is possible._*PRD_TYP*_ _*PRD_COD*_ _*90 Days Stock*_ _*Less than 90 and from the start of year Stock*_ _*2010 Stock*_ _*2009 Stock*_ ...and so on upto previous 5 years 1 2012001234 300 125 100 0 ...
Hello
kamranpathan wrote:
Dear Frank, thank you again for an impeccable answer. Sorry for a delay feedback coz I was sick of a fever. I tested the provided query u n that has worked well. but I did not understand then u points marked the end of the answer of the urs:Prs_date is a DATE: don't try to INSERT a VARCHAR2 value into a DATE column.
If 20/SEP/2011 ' is not the correct format, so what fix the Date Format?
In Oracle SQL, anything inside single quotes is a VARCHAR2. (There is an exception; I'll be back later.)
"a,"
'2' and
"the square root of 9'.
are all inside single quotes, so they are VARCHAR2s, not numbers. A human being who sees these chains might think of figures, but they are still VARCHAR2 strings and not numbers.
20/SEP/2011 '.
'September 21, 2011', and
'Yesterday '.
are all inside single quotes, so they are VARCHAR2s, not DATEs. A human being who sees these chains might think of DATEs, but they are still VARCHAR2 channels and not dates.
When you use the wrong data type (for example, when you use a VARCHAR2 in a place where we expect a DATE) Oracle will try niot very hard to trigger an error. It will try to convert a DATE VARCHAR2. Sometimes it can work, other times it cannot. It is never a good idea to expect that such implicit Conversion will work; You must always use the correct data type instead. For example, the prs_dte of the aging_test table column is a DATE. When you say:INSERT INTO aging_test (prs_dte) VALUES (x);
Oracle expects x as a DATE, so do not put some other datatype as a VARCHAR2 in place of x.
The TO_DATE function returns a DATE, so a correct is to INSERT a line in aging_test:INSERT INTO aging_test (prs_dte) VALUES (TO_DATE ('20/SEP/2011', 'DD/MON/YYYY'));
This is an example of a +Explict Conversion +. The TO_DATE function expects two arguments to be VARCHAR2s, and that's exactly what they are in the example above: the two arguments are of the literal string, enclosed in single quotes.
There is an exception, as I mentioned. When the DATE keyword (or TIMESTAMP) comes immediately before the first single quote, then single quotes, everything that comes between them and the keyword itself form a DATE literal (or a literal STAMP, but I'll just talk about DATEs in the future). The stuff between single quotes must be in YYYY-MM-DD format, otherwise you will get an error. So another acceptable way to enter a row in the aging_test table is:
INSERT INTO aging_test (prs_dte) VALUES (DATE '2011-09-20');
It is only as good as in the example above (those used TO_DATE), and has the same results. You can use any you like.
the age_prd can never be ' 'Less than 90 and from 01/01/2011'.
Yes my dear, in my case that I really need this period of aging, I don't know why, but sometimes, being a service Department (IT), we fullfuil insensitive logic of user.
Remember how BUSINESS works.
When you sayCASE WHEN c1 THEN r1 WHEN c2 THEN r2 END
the c1 State is evaluated first. If c1 is set to TRUE, then the CASE expression returns r1, and the rest of the CASE expression is not evaluated.
What happened in this CASE of expression, where x is a NUMBER?CASE WHEN x > 0 THEN 'Positiv' WHEN x = 2 THEN 'Zwei' END
This CASE expression will never return 'Zwei', because the condition "x = 2" is just a special case of the prior"x > 0". If this CASE expression is executed when x = 2, then the 'x > 0' condition is evaluated, it turns out be TRUE, and "Positiv" is returned. The following condition is not even considered.
In the expression you have posted:` Case When Age.Prs_Dte Between (Sysdate - 90) And Sysdate Then '90 Days' When Age.Prs_Dte Between (Sysdate - 61) And Trunc(Sysdate, 'RRRR') Then 'Less than 90 and from 01/01/2011' ...
the value 'less than 90 and since 01/01/2011' will never be returned. the condition "Age.Prs_Dte between (Sysdate - 61) and Trunc (Sysdate, 'RRRR') ' is a more narrow condition that" Age.Prs_Dte between (Sysdate - 90) and Sysdate. Any SYSDATE value which translates by "Age.Prs_Dte between (Sysdate - 61) and Trunc (Sysdate, 'RRRR')" TRUE will as a result in the previous state, "Age.Prs_Dte between (Sysdate - 90) and Sysdate" being TRUE.
If you need an expression BOX which will return sometimes 'less than 90 and since 01/01/2011', then do not use the one you posted. I don't know what you should use, because I do not understand your business needs. Post some sample data (CREATE TABLE and INSERT statements for a table with the columns prs_dte and sys_date), display the results you want sample data and explain how you get these results from these data, and someone will help you write a CASE expression that produces these results.
Only use "date3 BETWEEN date1 AND date2" when date1 and date3 are always midnight.
I really did not understand what point completely.
Sorry, I wasn't very clear. What I meant is that a lot of people make mistakes in using BETWEEN with DATEs, because they forget that all DATEs include hours, minutes, and seconds. If the hours, the mionutes and seconds all arrive at 0, then BETWEEN works the way they expect. When the hours, the minutes and seconds are not all 0, then these people are often confused.
For example, in my time zone is currently about 17:58 September 23, 2011, so at present, nor this condition:SYSDATE BETWEEN TO_DATE ( 'JAN/01/2011', 'MON/DD/YYYY') AND TO_DATE ( 'SEP/23/2011', 'MON/DD/YYYY')
or this condition
SYSDATE BETWEEN TO_DATE ( 'SEP/24/2011', 'MON/DD/YYYY') AND TO_DATE ( 'DEC/31/2011', 'MON/DD/YYYY')
is set to TRUE. Which can be confusing.
If change us one to tell us "SEP/24"instead of "SEPT. 23." /', then it would be a point in time (that is midnight on 24 September) when the above two conditions were TRUE. Which can be confusing.
Similarly, if we leave "SEP/23 ' in the first condition and change the second condition to say" SEP/23 ' rather than ' SEP/24 ', then there is also a point in time when both conditions are TRUE.»»» Which can be confusing.
I admit it is subtle and can be difficult to understand if you don't really understand how work DATEs.
If all goes well, it is easy to understand: don't use not BETWEEN with DATEs. The results are not what you expect if you don't really understand how work DATEs. -
How to calculate a date on a form?
I am working on a form for our clients and our staff to use and I asDects to calculate a date for another date. We currently use an Excel worksheet that works very well, but we begin to encounter customers who do not have access to Excel. Having the form of Adobe would give us more flexibility.
Here is an example of exactly what I need:
Last read Date: 01/01/00
Approximate Due Date_1: 26/01/00 (this is the Date of the last reading + 26 days)
Approximate Due Date_2: 26/02/00 (this is the Date of the last reading + 56 days)
Approximate Due Date_3: 26/03/00 (this is the Date of the last reading + 85 days)
Thank you
Check out this previous topic: http://forums.adobe.com/thread/836872
-
How to calculate the date from sysdate
I try to get 12/09/2009-12:51:30 by subtracting the current date to sysdate.I can get with this year, but I don't know how I can get to the date and the month preceding.
() Choose add_months (sysdate-36() of double) = 12/09/2010
Planned result 12/09/2010 13:23:30
Thank you for the help
I'm assuming that time is fixed if it is to see the example below.
SQL > select add_months (to_date (to_char(sysdate,'dd-mon-yyy') |)) (("" 12:51:30 ',' dd-MON-yyy hh: mi: ss AM "), - 36) prior_date
2 double;PRIOR_DATE
-----------------------
12 - Oct - 2010 12:51:30SQL >
-
How to calculate the date interval
Hi Experts,
I'm looking for a way to calculate the interval between two dates. And get the result to the format "dd.mm.yyyy hh24:mi:ss.
Best practices for a problem like this?select sysdate - to_date('1.1.2000 12:00:00','dd.mm.yyyy hh24:mi:ss') from dual
Best regards
Igorselect trunc( months_between( day2, day1 ) / 12 ) years , mod( trunc( months_between( day2, day1 ) ), 12 ) months , numtodsinterval( day2 - add_months( day1, trunc( months_between( day2, day1 ) ) ), 'DAY' ) rest from ( select to_date( '19-01-1979', 'dd-mm-yyyy' ) day1, sysdate day2 from dual )
-
How to calculate the data according to the fiscal
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March). I have a table INVOICE. CREATE TABLE INVOICE ( IN_NO NUMBER, IN_DT DATE, IN_DETAILS VARCHAR2(20 BYTE) ) I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012. What statement should i use to filter the data as above ? Sanjay
user12957777 wrote:
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March). I have a table INVOICE. CREATE TABLE INVOICE ( IN_NO NUMBER, IN_DT DATE, IN_DETAILS VARCHAR2(20 BYTE) ) I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012. What statement should i use to filter the data as above ? Sanjay
You should now learn to use correctly
tags select to_char(add_months(in_dt,-3),'YYYY') FISCAL_YEAR FROM INVOICE;
-
How to calculate the date fields while excluding Saturday and Sunday
Hi, I use Jdeveloper 11.1.3.4
I have an Oracle database and creates a table called holiday with 3 attributes:
user (VARCHAR)
(early)
end (date)
The idea is that you subtract the finish from the beginning and get a number of vacation days used. The thing is that the sum should exclude Saturday and Sunday.
Any way to do it?/* Formatted on 6/1/2011 7:57:32 AM (QP5 v5.149.1003.31008) */ WITH t AS ( SELECT id, MAX (strt) strt, MAX (finish) finish, SUM (dys) days_off FROM (SELECT id, strt, finish, CASE WHEN TO_CHAR (dy, 'day') LIKE 'saturday%' THEN 0 WHEN TO_CHAR (dy, 'day') LIKE 'sunday%' THEN 0 ELSE 1 END dys FROM vacations MODEL PARTITION BY (ID id) DIMENSION BY (0 d) MEASURES (POCETAK strt, KRAJ finish, POCETAK dy) RULES (dy [FOR d FROM 1 TO finish[0] - strt[0] INCREMENT 1] = (NVL (dy[CV () - 1], dy[CV ()]) + 1))) GROUP BY id ORDER BY id) SELECT t.id, t.strt, t.finish, t.days_off, vacations.korisnik, SUM ( CASE WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik ORDER BY t.id) this_years_running_total, SUM ( CASE WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik) this_years_grand_total, SUM ( CASE WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik ORDER BY t.id) next_years_running_total, SUM ( CASE WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik) next_years_grand_total FROM t, vacations WHERE t.id = vacations.id
id strt finish daysoff korisnik thisyrruntot thisyrtot netyrruntot nextyrtotal 1 5/25/2011 5/31/2011 5 Kantardzic 5 22 0 26 2 6/6/2011 6/13/2011 6 Kantardzic 11 22 0 26 5 6/1/2011 7/6/2011 26 Kantardzic 11 22 26 26 6 6/16/2011 6/30/2011 11 Kantardzic 22 22 26 26
-
How to calculate both date diff?
What is the function similar to the POET? as datediff = date1 - date2 statement SQL Oracle db,
I tried to use less, it wasn't works, POET does not support at least two directly?
Thank you very much!
IshmaelYou can use the timestampdiff function. TimestampDiff function returns the total number of intervals specified between two timestamps.
Syntax:
TimestampDiff (interval, time stamp-expression1, expression2-timestamp)
example TimestampDiff (SQL_TSI_DAY, date1, date2) returns the number of days between date1 and date2.
The specified interval. Valid values are:
SQL_TSI_SECOND
SQL_TSI_MINUTE
SQL_TSI_HOUR
SQL_TSI_DAY
SQL_TSI_WEEK
SQL_TSI_MONTH
SQL_TSI_QUARTER
SQL_TSI_YEAR -
How to calculate the number of days/weeks/months between 2 dates?
Hello
I would like to know how to calculate the number of days/weeks/months between 2 dates in OBIEE 11 g, for example, I have 26/05/2013 and 19/05/2013, then I want to get 7 days.
Thank you!
JamieHi Jamie,
Through this links...
http://www.bravesoft.com/blog/?p=682
http://twobiee.blogspot.in/2012/01/working-with-date-differences.htmlMark as correct it allows u...
Thank you... -
How to calculate an interval between two dates?
Hi all
I have two dates, and I need to know if the interval between the two is more than 30 days or not. I can't understand how to calculate this interval.
Could someone help me?
Thank you very much.See the following forumpost:
Re: Calculation of difference in date in BPEL
Kind regards
Melvin
-
the time of acquisition of data - how to calculate the rate of analog output
I want to calculate an acceptable rate of analog output, one that is taken in charge by material (PCIe6353), without the rate being changed by the VI DAQmx Timing (sample clock). The final objective is to have a rate of analog output that is an integer multiple of the analog input for precise frequency, since the sinusoid AO's amplifiers, which have a ringtone when AO updates occur.
According to 27R8Q3YF of the knowledge base: how the actual scanning speed is determined when I specify the rate of scanning to My d..., the rate is revised as needed by calculating the rate of clock / asked for advice, divide the result rounded downwards and upwards in the clock of the Board and use the one that is closest to the requested speed.
If 'Embedded clock' is selected, which is the result "Council clock. DAQmx sample clock timebase Timing node - SampClk.Timebase.Rate says 100 ms/s. However, for a rate resulting from the update of 2.38095MS / s, the divisor of the time base timing node - "SampClk.TimebaseDiv" gives a value of 42. 42 x 2.38095 M = 99, 999, 990, where it should be 100 ms/s.
How to calculate an acceptable rate of analog output is supported by the hardware? I have other plates, in addition, a general method would be appreciated.
I haven't worked all the details yet but noticed a few things that may be relevant.
Req AI rate isn't a whole ditch 1E8. It is used to determine the rate of the AO.
There is no check to ensure that the rate of the AO is an integer division.
It seems that you have the right idea, but the implementation is not yet there.
Lynn
-
Series Packet Question: How to calculate CRC
Hi all, I have tryied to find an answer on how to calculate the CRC on a RS232 packet received, its really driving me crazy!
im a beginner, learned how to use labview read on different forums, and I had managed to build really good applications, but im stuck in this, hope someone can help me...
OK, so im constantly receive packets of 15 bytes:
A5 09 0C 00 61 05 1F A0 10 00 05 00 04 05 3F
A5 09 0C 00 61 05 10 00 05 0C 2F 03 A0 1F-3F
A5 09 0C 00 61 05 10 09 05 09 04 09 A0 1F-3F
the supplier for material gave me the following code to calculate the CRC:
Control CRC program:
#define unsigned char uchar
UCHAR CRC_Bitwise8 (uchar * buf, uchar size)
{
UCHAR i, j, b;
UCHAR crc = 0;
for (j = 0; j<>
{
b = * buf ++;
for (i = 0; i<>
{
If (((CRC^b) & 0x01)! = 0)
CRC ^ = 0x18;
CRC > = 1;
b >> = 1 ;
}
}
return crc;
}so my question is, how can we insert this code in labview? any example?
Thanks in advance, this forum has really helped me learn labview in a practical way.
You can use my code for the thread that I've referenced. To play with a web version of my code go here. My code is based on the code on this Web site.
My code to the following parameters:
Calculation of the CRC: Other (specify)
Order of the CRC: 8
Polynomial CRC: 0 x 30
CRC initial value: 0
CRC XOR final value: 0
Reflect the preprocessing of data: TRUE
Match the data before Final XOR: TRUE
In your messages, the A5 09 0c is certainly a header. I think that the 00 following is also part of the header, but without the manual, I can't confirm. 00 will not affect the calculation of the CRC, in order to get the same results with it and without it. So, in your first example, I use 61 05 3F 1E A0 00 05 00 04 10 and the result is 0x05.
-
How to calculate the polynomial graphic adjustment of waveform
Hi all
I am new to lab - view so would need a little assistance in one of the problem I have right now.
My problem is: how to calculate the polynomial graph of waveform data adjustment? I need to convert the waveform to XY graph data, and then use the polynomial vi made integrated to calculate the fitting?
Detail: My problem is that I have waveform graph, I calculate the vertices and the Valley, but because of the noise, my peaks and Valley detection is sometimes not exact, so to smooth the chart that I must apply the polynomial fit.
If anyone can help me in this, I'll be very grateful.
Thanks in advance
Hi Omar,.
have you seen the suggestion of Lynn above?
You already have the values of Y (your table). Now, you need build the table of X as indicated, only to replace the value of dt with your spacing from point to point. Somewhere in your code, you know that the value that you have an x-axis indicated in milliseconds...
-
How to calculate the size of HFM Cube in SQL Server 2005
Hello
How to calculate the size of the HFM Cube in SQL Server2005
Under application used to Oracle. So what's application to SQL Server?
***********************************************************************************************************
SQL > select sum(bytes/1024/1024) from dba_segments where nom_segment like 'FINANCIAL_ %' and owner = 'HFM;
SUM(BYTES/1024/1024)
SQL > select sum(bytes/1024/1024) from dba_segments where nom_segment like FINANCIAL% HSV' and owner = 'HFM;
SUM(BYTES/1024/1024)
**********************************************************************************************************
Concerning
SmileeWhat is your goal? The subcube in HFM is a concept that applies to application layer - not so much to the database layer. The size of the subcube is the unique number of sheets (data values for January - December inclusive, for example) for the given entity, a triplet of currency or node Parent.Child. Should be considered for accounts of parent and customs that do not exist in the database, but are calculated in the RAM of the application layer.
So if your goal is to find the largest subcubes, you could do this by querying the database and by counting the number of records per entity value (tables DCE) or combination of entity parent.child (tables of the DCN). I am not versed in SQL, but I think the script below you would just the size of the pattern and not the sizes of subcube.
See Accelatis.com for a third party software product that can do it for you. The function is called the subcube Analyzer and was written by the same team that wrote HFM, then they should know how :-)
-chris
-
How to calculate the 99th percentile of a stream of number...
Environment:
Oracle 11.2.0.3 EE on Solaris 10.5
I have a stream of numbers (for example 1000), I need to calculate the 99th percentile of the distribution of this stream in such a way that when a new ' number is introduced, I can tell if the new number is above the 99th percentile of the distribution of my workflow.
I don't have a good idea of the nature of the distribution if it's important.
I am NOT, I repeat NOT a statistician! :-)
I read the docs on the different functions available, ntile, percent_rank, percentile_cont, percentile_disc, etc. I also read a lot of articles referenced via Google.
The examples are not exactly what I'm trying and I was unable to get the result I need by trial and error (mostly!).
All suggestions are welcome!
If you need additional information, I will try to provide what I know.
-garyHi, Gary.
garywicke wrote:
Hi FrankWell to try to facilitate the description of periods, I managed to confuse the issue a little more.
Sorry about that.
I need to use days not months. The script will be executed every day and watch period of ago 210 days to 31 days following there from 30 days at present.
With respect to the expected result, I need somehow calculate what turnover represents the 99th percentile (or 90th everything that works in the example) and store that in my table of this customer.
Then after a CREATE TABLE statement for this table and you want that it contains, given the data published in the sales table, after it is filled.
Another process on the whole will consider the last average of 30 days and determine if this average exceeds sales 99th percentile figure and initiate an action (alert email, etc.) if it is.
My problem is that I don't know how to calculate this 99th percentile number.
After the sample data, I'm guessing it should be close to the number of SD 3, but after reading your comments, maybe that's not correct.
That's my guess. Sometimes deviations corresponding to percentiles, sometimes they did not. People choose one or the other, depending on what amounts to their data, and what they want to show on these data. Your client has apparently chosen percentile. Unfortunately, we do not seem to know something about the problem.
Before you can solve this problem for your customer, you must understand what the problem is. Talk to your client and know exactly what is wanted here.Here is one possible approach.
WITH got_month_avg AS ( SELECT custno , AVG (amount) AS month_avg FROM sales WHERE tran_dt > SYSDATE - 30 AND tran_dt <= SYSDATE GROUP BY custno ) , got_threshold_amount AS ( SELECT DISTINCT custno , PERCENTILE_CONT (.4) -- or .99 WITHIN GROUP (ORDER BY amount) OVER ( PARTITION BY custno ) AS threshold_amount FROM sales WHERE tran_dt > SYSDATE - 210 AND tran_dt <= SYSDATE - 30 ) SELECT a.custno , a.month_avg , t.threshold_amount FROM got_month_avg a JOIN got_threshold_amount t ON t.custno = a.custno --WHERE a.month_avg >= threshold_amount ORDER BY custno ;
Output:
` CUSTNO MONTH_AVG THRESHOLD_AMOUNT ---------- ---------- ---------------- 5 126.5 4812.6 26 4602.44444 3102.2
I set the WHERE clause comment, just so that we could see the results of each custno. I also put the extremely low threshold (40th percentile) just for a custono would be selected if you are not using the WHERE clause.
Subqueries are average in the last 30 days and the 40th percentile for 180 days before that. Let's take a look at custno = 5. There were two rows in the last 30 days (225 and 28 amounts), then the average in the last month is (225 + 28) / 2 = 253 / 2 = 126,5.
Within 180 days prior to that, he had 7 amounts, in ascending order:
1st (0th percentile): 647
2nd (17th percentile): 1869
3rd (33rd percentile): 3065
4th (50th percentile): 7434
5th (67th percentile): 8435
6th (83rd percentile): 9393
7th (100th percentile): 9712
Since (for now), we are interested in the 40th percentile. It will be more than number 3065 (33rd percentile) and less than 7434 (50th percentile), 3065 to 7434, somewhat 40% being somewhat closer than 33% to 50%. This number turns out to be 4812.6.
Maybe you are looking for
-
Mac Mini 2011 - AMD Radeon GPU failure
Hi all I meet my mini 2011 (AMD video card) the same problem as the MacBook and iMac to the same generation.Apple launched an extended warranty for Imac: iMac (27-inch): AMD Radeon 6970 M video card replacement - Apple Support program MacBook: http:/
-
Want 4504: cartridge hp 21 instead of 301 hp
I just wanted to know if my old HP 21 ink cartridge would work in my new Envy 4504 printer rather than a 301 hp?
-
Context-sensitive help in LabVIEW truncated to 8000 characters.
How do I get more details?
-
Windows Server R2 2012 unexpected restart
Hi guys,. I have a problem with one of my DELL servers running Windows Server 2012 R2 Std. It is a new Server Power Edge R630. The problem is that it has restarted unexpectedly by itself. So far, it has happened twice. I raised this issue to DELL tec
-
having a problem with my fs 2004-flight - path approach to land - can not get the hands on the dial LOC to meet