Calculation of the average

Hello

I'm figuring the average of some values divided by ID & month.

Please see test the scripts below, I use Oracle D/B v 11.2.0.4:

CREATE TABLE TEST)
IDENTIFICATION NUMBER,
MONTH, DATE, TIME,
CUST_NUM VARCHAR2 (4).
RATE 1 NUMBER,
NATUREL2 NUMBER);


INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0001", 26.35, 78.45);
INSERT TEST VALUES (4586, 1 JANUARY 13 ', ' 0002', 13.21, 33.33);
INSERT TEST VALUES (4586, 1 JANUARY 13 ', ' 0003', 54.69, 79.34);
INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0004", 99.36, 100);
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0005', 89,63, 78.25);
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0006', 13.11, 49.36).
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0007', 78.63, 85.21);
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0009' 63,22, 100);
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0010' 22.35, 100);
INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0011', 41.11, 99,63);
INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0012', 25.23, 45.25);
INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0013', 13.11, 56.54);
INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0014', 56.24, 50.00);
INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0015', 11.23, 100);
INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0016', 100, 100);
Insert test values (4586, 1 March 13 ', ' 0017', 99.99, 99,63);

I want to calculate the average of the rates of column 1 by id & months but the request is also a grouping of the cust_num:

SELECT ID, MONTH, CUST_NUM, AVG (CASE WHERE rate1 <>0 then end rate1) avg
OF THE TEST
Group by id, month, cust_num
order by 2, 3

Expected results:

4586, 13, JANUARY 1, 0001 48.40
4586, 1 JANUARY 13, 0002, 48.40
4586, 1 JANUARY 13, 0003, 48.40
4586, 1 JANUARY 13, 0004 48.40
4586, 1ST FEBRUARY 13, 0005 51,34
4586, 1ST FEBRUARY 13, 0006 51,34
4586, 1ST FEBRUARY 13, 0007 51,34
4586, 1ST FEBRUARY 13, 0009, 51,34
4586, 1ST FEBRUARY 13, 0010 51,34
4586, 1ST FEBRUARY 13, 0011 51,34
4586, 1 MARCH 13, 0012 41.16
4586, 1 MARCH 13, 0013 41.16
4586, 1 MARCH 13, 0014 41.16
4586, 1 MARCH 13, 0015 41.16
4586, 1 MARCH 13, 0017 41.16


The average should be the same for each id and the month, can anyone help?

Thank you

Hello

sliderrules wrote:
Hello

I'm figuring the average of some values divided by ID & month.

Please see test the scripts below, I use Oracle D/B v 11.2.0.4:

CREATE TABLE TEST)
IDENTIFICATION NUMBER,
MONTH, DATE, TIME,
CUST_NUM VARCHAR2 (4).
RATE 1 NUMBER,
NATUREL2 NUMBER);

Thanks for posting the CREATE TABLE and INSERT the statementsl which is very useful.

INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0001", 26.35, 78.45); ...

The month of the column is a DATE; do not try to insert values such as 1 January 13 VARCHAR2' in a DATE column.

I want to calculate the average of the rates of column 1 by id & months but the request is also a grouping of the cust_num:

GROUP BY means that, regardless of the number of rows in each group in the table, you want to only 1 row of output for the whole of the group. In this case, you won't have the output to have exactly the same number of rows as the table? If so, then do not use GROUP BY.

SELECT ID, MONTH, CUST_NUM, AVG (BOX WHEN rate1 <> 0 then end rate1) avg
OF THE TEST
Group by id, month, cust_num
order by 2, 3

Expected results:

4586, 13, JANUARY 1, 0001 48.40
4586, 1 JANUARY 13, 0002, 48.40
4586, 1 JANUARY 13, 0003, 48.40
4586, 1 JANUARY 13, 0004 48.40
4586, 1ST FEBRUARY 13, 0005 51,34
4586, 1ST FEBRUARY 13, 0006 51,34
4586, 1ST FEBRUARY 13, 0007 51,34
4586, 1ST FEBRUARY 13, 0009, 51,34
4586, 1ST FEBRUARY 13, 0010 51,34
4586, 1ST FEBRUARY 13, 0011 51,34
4586, 1 MARCH 13, 0012 41.16
4586, 1 MARCH 13, 0013 41.16
4586, 1 MARCH 13, 0014 41.16
4586, 1 MARCH 13, 0015 41.16
4586, 1 MARCH 13, 0017 41.16

The average should be the same for each id and the month, can anyone help?

Use the analytical AVG, not the aggregate function.

SELECT    id
,        month
,        cust_num
,        AVG (NULLIF (rate1, 0)) OVER ( PARTITION BY  id
                                               ,            month
                           )     AS avg_rate1
FROM      test
ORDER BY  month
,            cust_num
;

Tags: Database

Similar Questions

  • calculation of the average value of the sorted data and polar route drawing

    Hello

    I did a VI that calculates the average value of the wind rotor/speed-ratio in the sections of 30 degrees (wind direction). He also called the polar plot of calculated data. Everything works, but I would like to make more detailed calculations and drawings, by increasing the resolution to 1 degree, or...

    Problem is VI, I did, is not easy on a large scale. At the moment, I have 12 parallel structures of switch-box to calculate the average value and build the array function to collect data calculated for Polar plot to draw the image in real time. I know it's probably the worst way to do it, but since I have done a few things with LV, it was the only way I managed to do what I wanted.

    Now, if I continue in same way to reach my goal, I have to create 360 Parallels switch-case structures... that are crazy.

    Something like the calculation of the average of the table or matrix (zero/empty values should not be calculated on average) inside the loop or similar way would probably be the best solution.

    So, polar plot drawing is not a problem, but creating a reasonalbe average metering system is. Any ideas?

    I would also like to rotare northward to the top (0 deg), and degrees of increase in a clockwise direction on polar ground dial plate (as on the compass).

    VI on the attachment. (simplified version of the complete system)

    I have signals:

    -Wind speed

    -wind direction

    -Rotor speed

    I want to:

    -calculate the average value of the speed of the wind / rotor - ratio in sections (5 degrees, 1 degree)

    -Draw a polar path of the wind rotor/speed-ratio of averages in propotion of wind direction

    I'm using LabView 2009

    Thank you very much.

    It is closer to what you're looking for?

  • exclusion of a calculation of the average value

    Hello people from Adobe,.

    I am trying to exclude the "NC" 10 value are used to fill an average value (average rating of text box) on a form, I created.  I used the script from another topic on the exact topic thread, but I modified to fit my needs.  I think that it is a quick fix very.  For some reason, I don't get the average of all 10 drop boxes in my text box.  Can someone check this script and see what I might be missing.  The text box displays '0' because of this line event.value = 0;

    What Miss me?

    Here is the code:

    Average values of non - NA;

    var aFieldNames = new Array ("ListeDéroulante1", "Dropdown2", "Dropdown3", "Dropdown4", "Dropdown5", "Dropdown6", "Drop-down list 7", "Dropdown8", "Dropdown9", "Dropdown10");

    counter to the values non - NA;

    var nCount = 0;

    variable for values of sum of non - NA;

    nSum var = 0;

    default value of result if no average not calculated;

    Event.Value = 0;

    Table of process of domain names;

    for (i = 0; i < aFieldNames.length; i ++) {}

    If (this.getField(aFieldNames[i]).valueAsString! = "NA") {}

    field doesn't have a value of "NA";

    nCount ++; incrementing counter

    nSum += Number (this.getField(aFieldNames[i]).value). Add the value of the sum

    } / / end of value not of NA;

    } / / end of treatment a loop field;

    calculate the average;

    If (nCount! = 0) {}

    divisor of zero, so we can calculate the average;

    Event.Value = nSum / nCount;

    }

    I noticed that there 'Dropdown 7' as opposed to 'Dropdown7', which is what the field other names are similar. Could this be it?

  • calculation of the average using sql

    Hi all

    My table structure is

    --------------------------------------
    ID name notes starting_date end_date
    --------------------------------------


    workingdays = end_date-starting_date


    I had a query


    Select name, max (case when remarks = remarks then end notes).
    Max (case when id = id then end_date-starting_date end),
    AVG(end_date-starting_date) average t_action_items
    Rollup (name, end_date-starting_date) group;


    who's out like that

    Name of the average Workingdays remarks
    --------------------------------

    x 20 20 aaa
    BBB 10 20 x
    AAA 10 15
    y ccc 19
    DDD y 8
    CCC 8 13.5
    CCC 8 14.2

    But I need output like this, how can I do that someone please guide me

    Name of the remarks Workingdays
    ------------------------

    aaa 20 x
    BBB 10 x
    15 > x average
    y ccc 19
    DDD y 8
    13.5-> average for y


    Forgive me, I can't able to align to the right format, I think that with data you can seggregate

    Thanks in advance...

    Published by: Paappu on March 20, 2009 09:50

    Hello

    I have used WITH clause to show the result. You use just SELECT it with your table it will work.

    SQL> SELECT * FROM T;
    
    NAME   REMARK        START_DT  END_DT
    ------ ------------- --------- ---------
    Mark   Design        15-FEB-09 15-FEB-09
    Hendry Coding        08-JUN-08 15-JUN-08
    steve  Testing       29-OCT-08 04-NOV-08
    JAMES  POC           01-MAR-09 01-MAR-09
    JAMES  DOCUMENTATION 01-MAR-09 09-MAR-09
    
    SQL>     SELECT Name,Remark, SUM(work_hrs), AVG(work_hrs) FROM (
      2      SELECT name,remark ,start_dt,end_dt,SUM(end_dt-start_dt) OVER (PARTITI
    N BY name,remark ORDER by Name) work_hrs
      3      FROM T)
      4    GROUP BY ROLLUP(name,remark);
    
    NAME   REMARK        SUM(WORK_HRS) AVG(WORK_HRS)
    ------ ------------- ------------- -------------
    Hendry Coding                    7             7
    Hendry                           7             7
    JAMES  DOCUMENTATION             8             8
    JAMES  POC                       0             0
    JAMES                            8             4
    Mark   Design                    0             0
    Mark                             0             0
    steve  Testing                   6             6
    steve                            6             6
                                    21           4.2
    
    10 rows selected.
    
    SQL>
    

    Kind regards

  • The problem with the calculation of the average for the recurring value

    My task is to perform analysis, where in the table have ID to which she is assigned 10 measures (1-10) and each has its own value. I have to average of this what I take AVG (as) and I want to say. However, as prompcie Will I choose the second ID and I have two measures 1-10 time what I means account for 20 photos and I want to separate Average (two - each for 10 measures). Is there any possibility of Smash it? The use of a function or collection of rehearsals ?


    It looks like this:


    column 1 | column 2 | column 3 | AVG |


    ID |  Nr.  result | AVG?

    x | 1. 200 | AVG x?

    | 2. 210 |

    | 3. 210 |

    There | 1. 210 | is AVG?

    | 2. 208

    | 3. 200


    In column 4, I want to be avarage but another for id x and another for id y?

    is the result you are looking for:

    If Yes... then avg column formula is AVG (result BY id)

  • Calculate the average per slot?

    Hi Chaps,

    I am a beginner on numbers (almost everything on Mac I would say) and I need help to calculate average values.

    These are calculated values (column 2) taken on a specific time of the day (column 1).
    I managed to create a third using a built-in function to get the time slot (column 3).

    14:58:42

    235

    14

    14:59:42

    274

    14

    15:00:50

    7937

    15

    15:01:55

    5157

    15

    16:02:57

    1822

    16

    16:03:57

    207

    16

    Can please somebody see me step by step how to calculate the average by time slot as below?

    14

    254,5

    15

    6547

    16

    1014,5

    Kind regards

    Stone

    This can help you

    Assuming you data in a table named 'Data' and the information is summarised in another table (right) named "Summary".

    Select cell B1 in the summary table and then type (or copy and paste from here):

    = SUMIF(Data::C,a1,Data::B) ÷COUNTIF (Data::C, a1)

    shortcut for this is:

    B1 = SUMIF(Data::C,a1,Data::B) ÷COUNTIF (Data::C, a1)

    Select cell B1, copy

    Select column B, paste

  • 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.

  • Read TDMS - calculate the average

    Hello

    I have data I stored in a PDM file, I want to do some calculations, such as finding the average of all of my data.

    Successfully, I have read the PDM file and linked to a waveform graph, no problem on this part.

    However, I'm stuck trying to figure out how can I access data other than just to print them on a graph.

    How could I summarize all the values to find the average value?

    I am using LabVIEW 2010.

    Thank you.

    Use the Mean.vi function under the probability and statistics.  I'm guessing that you read a wave form and you may need to remove the values of Y by using the function to get the elements of waveform.  Display code if you get stuck.

  • Filtering and calculate the averages for subsets of a table

    I have a 2D picture that comes out of a loop, and I need to calculate the average of the subsets corresponding to iterations 0-9, 10-19, etc...  In addition, I need to filter the values above and below acceptable limits before calculating the average.  Any suggestions for how to address the issue?

    Here are examples of code does exactly that. This post, looks like you need an upper limit as well. I'll leave that as an exercise for you.

  • Calculation of the time wall of a SQL query.

    Hello

    While trying to discover the time of running a SQL query (wall time) I read in one place that CPU_TIME/EXECUTIONS of v$ SQLAREA, is the precise runtime we can come close to.

    I can't use "set timing on ' or 'DBMS_UTILITY. GET_TIME' that I need to extract the execution time of the story because the query will be drawn to an end, and I need to know how long it took to DB level and compare it with the end time before calculating the % of time used in the DB level total.

    Maybe another way to track sessions and the user TKPORPOF but now I donot want to take the help of the ADMINISTRATOR at this initial stage.

    Is CPU_TIME/EXECUTIONS of v$ SQLAREA where (SQL_TEXT) AS "SELECT... OF... %'; should be enough?

    user2925917, yes as Brian already answered your understanding as posted above seems correct.  Except in the case where there has been only a running query you will download an average time.  The problem with averages is that one or two unusual executions that can skew the average, but in most cases the average will be probably fairly accurate.

    - -

    HTH - Mark D Powell.

  • Change in the calculation of the threshold of IOPS / s between 5.1 and 5.5

    Hello world

    Some of my users complained about the performance degraded after that I migrated the host of 5.1 to 5.5. After a bit of poking around, I had to remove the limits of PAHO are / s in order to restore their previous performance...

    So, I did a simple test on the 2 VMs. Here's the info about the test:

    A host running vSphere 5.1, with SSD (OCZ ZDrive R4) card connected. A vm W2k12 R2 running on it, version 9 of vm, vmtools build 9221. 2-disc limited to 500 IOPS / s of each, so 1000 Ops ARE / s total

    A host running vSphere 5.5, same card plugged SSD. A clone VM vm first, version updated to 10, vmtools build 9349. IOPS / s limit matches

    Storage I/O control is disabled on the 2 hosts, but I did a few tests with active IGCs, and it was not conclusive

    Operating mode:

    1 take this http://vmktree.org/iometer/OpenPerformanceTest32.icf file

    2 IOMeter v1.1.0 Iometer project - downloads, pre-build binary for x 86-64

    3. has launched the 'Max - 100% read throughput' specification without change, outside of the "transfer request size. I changed this setting from 8 KB to 512 KB

    limit_iops.png

    Here are the results:

    limit_iops002.png

    As you can see, the limitation is handled completely differently from one version to the other... In addition, the average response time is crazy on the ESX 5.5!

    I searched for an explanation for this change, but I can't find anything...

    So, how can I go back to the old behavior? Because we have different types of workload and the different types of IO size, I can't have a simple formula to get an appropriate limit. I have to have a strict limit of the IOPS / s, regardless of their sizes...

    Thank you all,

    -Vincent.

    Hi all

    After an open case and dozens of tests, I found these links, explaining this beahviour "weird":

    New scheduler used in vSphere 5.5 disk i/o

    vSphere 5.5 and limits of disk (caveat mClock scheduler)

    In short, the new introduced in vSphere 5.5 disk IO Scheduler consider an e/s with a maximum of 32 KB. If your IOs are larger, when you specify a limitation of IO, the calculation will be in multiples of 32 KB... Please, read these links, Duncan explains really well... Congratulations to him!

    I'm just annoyed that VMWare does not communicate enough on these changes, because they are big enough!

    Kind regards

    Vincent.

  • WAIT % - % IDLE, what is the average for a virtual machine?

    I did some research on performance of VM problems and worked with the media to see that there is maybe a bottle neck IO that occur with a virtual VMware machine I have performance problems on. The technician found that the WAITING % - % IDLE on average for this virtual machine is around 200%. The tech said it was abnormally high. I forgot to ask her what was normal but wanted to put a post to see if some people out there know what they are on average. What is an average number of see? I have the system done nothing right now and I see 579% waiting and 372% IDLE. The technology has been able to confirm that no IO queue was occurring in the VMkernel or on the HBA controller.

    Some average % positions would be useful. Thank you.

    gdewulf18480 wrote:

    Supposibly the amount of time in a State of waiting for I/O is the WAIT - IDLE % difference. I was wondering if anyone had the numbers for this feeling. Is there anyone with some of them?

    Q: How will I know the VCPU world waiting for I/O events?

    A: WAIT - % IDLE % can give you an estimate on how much time processor is spent waiting for I/O events. It is an estimate only, because the world wait perhaps for other than the i/o resources. Note that we should do it only for the worlds of the WWW, not the other kind of worlds. Because the VMM worlds represent the best guest behavior. For the disk i/o, another alternative is to read the disk latency stats that we explain in the drive section.

    WAIT % by itself cannot be used, you must develop and examine the individual vCPU % EXPECTATION values and subtract their idle time.  You can't do it on the initial view of a single line by VM CPU in esxtop.  If technology that you mentioned did not explain it, he doesn't know what it takes.

    I have lots of virtual machines that are never less than 300% when I wait - % idle and I have no problems.

    It is an example, I caught NimSoft server:

    DHSNMS1 100 100 5 192.63 193,80 0.24 0.03 291,44 1.04

    %EST USED (s) 192 - in other words, almost two processors are used 100%

    The %Idle is 1.04% WAIT 291.44 - according to the calculation of waiting idle, I have a super serious problems of e/s past  But this isn't the case, and expanding, I can see that.

    5665 vmware-vmx 100 1 0.09 0.11 100.00 0.00 0.00 0.01

    5667 100 vmassistant.566 1 0.62 0.65 99,63 0.00 0.00 0.00

    5703 100 mks:DHSNMS1 1 0.01 0.01-100.00 0.00 0.00 0.00

    5704 vcpu 100 - 0:DHSNMS1 1 32,35 32.88 67,28 0.28 0.11 67,14

    5705 vcpu 100 - 1:DHSNMS1 1 31,58 32.05 68.11 0.00 67.85 0.12

    So the changed values unfortunately because of ESXTOP bike when you develop... which is annoying, but anyway.  In this you see % waiting is 67 and 68 with another respectively being 3 to 100% (which is normal) and the idle being %, 0, 0, 0, 67 and 67.8.  Doing the calculation on the processors shows a wait - slowed virtually 0 - or very little IO wait past with processors.  But if you add up all the expectations of % and % is idling, you have 434ish, and the 134ish and do the calculation is the difference of 300 - which is the 3 who are always 100%.

    So there is no way we can answer your question, we can only help you to understand how the values should be interpreted.

    Waiting for i/o States almost always go on the disc anyway, it is unlikely, therefore, the network or the user entered, looking at the stats of disc ESXTOP is a much better way to determine if there is a problem of e/s.

  • Query to retrieve the average growth rate

    Hi all

    10.2.0.5 on solaris

    Table script:

    DB_SPACE_HIST
    (
    DATE TIME STAMP,
    TOTAL_SPACE NUMBER (8).
    USED_SPACE NUMBER (8).
    FREE_SPACE NUMBER (8).
    PCT_INUSE NUMBER (5.2).
    NUM_DB_FILES NUMBER (5)
    );

    Sample data:


    Timestamp: / 16/2010 12:57:52 AM
    Totak space: 678017
    Used space: 235612
    Free space: 442405
    PCT in use: 34.75
    number of files: 60


    We have the timestamp stored in the table for more than 3 years. The requirement is that we get the average growth in the database per month.

    No idea how I can do this?

    Kai

    Start by getting your data used_space by month:

    select
    trunc(timestamp,'MM') mth,
    max(used_space) used_space_end_mth
    from db_space_hist
    group by
    trunc(timestamp,'MM');
    

    Then you can use the analytic function LAG to get used_space_end_mth compared to the month previous for calculating growth:

    select
    mth,
    used_space_end_mth - lag(used_space_end_mth) over (order by mth) growth
    from (
       select
       trunc(timestamp,'MM') mth,
       max(used_space) used_space_end_mth
       from db_space_hist
       group by
       trunc(timestamp,'MM')
    )
    order by
    mth;
    

    And finally, you can simply select the average growth:

    select
    avg(growth) avg_growth
    from (
       select
       mth,
       used_space_end_mth - lag(used_space_end_mth) over (order by mth) growth
       from (
          select
          trunc(timestamp,'MM') mth,
          max(used_space) used_space_end_mth
          from db_space_hist
          group by
          trunc(timestamp,'MM')
       )
    );
    
  • to get the average balance of an account

    Hello all :),.

    I have the table according to 'account_details '.

    account balance transaction_date
    1 100 1/1/2011
    1 200 1/5/2011
    1-100 1/20/2011
    500 1 31/1 / 2011
    1 200 3/3/2011
    2 100 6/2/2011


    account-> account number
    Balance-> This account balance
    transaction_date-> date of the transaction.

    I am required to calculate the average balance for each account for each month of the current year given only positive balances only. Phew! try to get any easier...

    ex: account = 1
    AVG (for January) balance = [100 * (5-1 + 1) + 200 * (31-5 + 11) + 500 * (31-31 + 1)] / 31
    (see-100 was ignored)

    AVG (for Feb) balance = 500 * 28] / 28

    I need to display the account number, the month and the year and the average balance for that month. [for all 12 months of the date of today ' hui]


    Thanks in advance for all the geniuses out there :)

    PS I am using oracle 10 g

    Published by: user12288152 on April 8, 2011 12:51 AM

    Hello

    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data and also to post the results desired from these data. It's great to describe the results, but don't forget to actually post them, too.
    Here are the results you want?

    `  ACCOUNT A_MONTH   AVG_BALANCE
    ---------- --------- -----------
             1 01-JAN-11      196.77
             1 01-FEB-11      500.00
             1 01-MAR-11      260.00
             2 01-FEB-11      100.00
             2 01-MAR-11      100.00
    

    Always tell what version of Oracle you are using. The following query will work in Oracle 10 (or higher).

    A way to do what you asked is:
    (1) to generate a list of all the dates in whioch you are interested
    (2) - outer join this list to your real data (balances only)
    (3) use the analytical LAST_VALUE function to copy each subsequent dates with NULL balance balance (I called this effective_balance)
    (4) take the average, per month
    It's

    WITH     all_dates     AS
    (
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT      DATE '2011-01-01'     AS start_date
                   ,     DATE '2011-03-10'     AS end_date
                   FROM     dual
              )
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    )
    ,     daily_balance     AS
    (
         SELECT     TRUNC (da.a_date, 'MONTH')     AS a_month
         ,     de.account
         ,     LAST_VALUE (de.balance IGNORE NULLS)
                   OVER ( PARTITION BY  de.account
                          ORDER BY          da.a_date
                        )               AS effective_balance
         FROM          all_dates     da
         LEFT OUTER JOIN     account_details     de  PARTITION BY (de.account)
                                 ON     de.transaction_date     = da.a_date
                                 AND     de.balance          > 0
    )
    SELECT       account,       a_month
    ,       AVG (effective_balance)     AS avg_balance
    FROM       daily_balance
    GROUP BY  account,       a_month
    HAVING       COUNT (effective_balance)     >= 1
    ORDER BY  account,       a_month
    ;
    

    Step (1) is made in the first auxiliary request, all_dates.
    Both steps (2) and (3) are made in the following subquery, daily_balance.
    Step (4) is made in the main query. This can be done in the same query as step (3), because the aggregate functions are calculated before analytical functions in the same query.

    Of course, you don't have to encode in the start_ hard and end_dates, as I did above. You can switch to the query into variables, or them are derived from data in the tabel and/or SYSDATE or any combination of methods.

    Published by: Frank Kulash, April 8, 2011 08:39
    Added to the explanation.

  • JavaScript to calculate the average of a column

    I have my PDF file I'm trying to calculate the average in a column of fields.

    My problem is that there are 7 areas, but all 7 can be omitted, so I think I need some sort of statement 'if' that would only count the number of fields containing values.  Then, somehow working in the rest of my calculation...

    That's what I have so far...

    (function () {}

    Get all the field values, as numbers
    var v1 = + getField("column.0").value;
    var v2 = + getField("column.1").value;

    var v3 = + getField("column.2").value;

    var v4 = + getField("column.3").value;

    V5 var = + getField("column.4").value;

    var V6 = + getField("column.5").value;

    v7 var = + getField("column.6").value;

    var V8 = + getField("column.7").value;

    Calculate the result and the value of this field
    Event.Value = (v1 + v2 + v3 + v4 + v5 + v6 + v7) / the number of fields that have been filled;

    })();

    I'm pretty new to javascript. Any help would be greatly appreciated! Thank you

    First of all, I woul write this function withou field reference to make it more universal, and then I have a funcion of document level so it could be used more than once in a PDF document and easily put into another PDF file.

    function Avg() {}
    average computer of the last non-empty field names
    var sum = 0; sum of the fields
    var number = 0; meter for non-empty fields
    for (i = 0; i< arguments.length;="" i++)="">
    iField var = arguments [i]; get the element of arguments passed
    var fField = this.getField(arguments[i]).value;
    If (!) isNaN (fField)))) {}
    field is a number
    If (fField.ToString ()! = ") {}
    field is not null or empty
    sum += Number (fField); Add to the sum
    Count ++; County of increment
    } / / do not blank end
    } / / end of number
    } / / end of loop iterative arguments
    If (count! = 0) {}
    calculate the average if there is one or more items on average
    to return the sum / count; Returns the average
    } else {}
    return ";
    } / / no end no average calculated
    } / / end of function Avg

    Your custom calculation script would then become:

    Event.Value = Avg ("column. 0', 'column.1', 'column.2', 'column.3', 'column.4', 'column.5', 'column.6', 'column.7');

Maybe you are looking for