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.

Tags: Database

Similar Questions

  • Get the average of the measurements in an image

    Hello everyone.

    First of all I thank very you much to be able to help and read this post.

    I'm trying to measure an object. Do I use the CLAMP block (horizontal clamp, it doesn't matter if it's the distance max or min).

    The problem is that you can calculate the maximum distance or minimum between the edges which lie in a return on investment with this VI.

    But I would get the average of all measurements in the KING, because it can be obtained because this VI use them to know what is the maximum and the minimum, but the problem is that I do not how to access.

    Any ideas to get the average?

    Thank you very much.

    I suggest using the IMAQ rake instead of the clip because it returns all edges detected.

    Take a look at the attached vi, I started from the example of the clamp vi and adding an option of rake.

  • [Labview] I want to get the average value in each new 100 samples.

    Hello. I'm Sophie.

    I'm studying Labview for my research.

    For me, the sampling frequency is 125KHz.

    I want to get the average value in each new 100 samples.

    Therefore, I want to get an average value of 1 ~ 100th samples and store this average value. Call assets(1).

    Then, I want to get an average of 101 ~ 200th samples and store this means value, call moyen2.

    .

    .

    .

    .

    I don't know how me I want.

    Thank you

    Sophie.

  • When I try to use a MS fingerprint reader I get the message "no mapping between account names and security IDS was done."

    Original title: fingerprint digital mapping

    When I try to use a MS fingerprint reader I get the message "no mapping between account names and security IDS was done."

    I tried the fix (http://support.microsoft.com/kb/890737?wa=wsignin1.0) without success.

    Any ideas?

    Hello

    Have you tried to reinstall the fingerprint reader, as mentioned in the previous post article?

    If your computer is on a domain, the question you posted would be better suited for the IT Pro TechNet public. I would recommend posting your query in the TechNet Forums to get help:
     
    For more information, see the articles:
     

    Hope the helps of information.

    Let us know if you need help with Windows related issues. We will be happy to help you.

  • How to get the average time of the day

    Hello

    Oracle 11g R2. Looking for a way to determine an average duration of the day. The data in the table are the following and are stored as VARCHAR2. These data represent the time of day a work finished and is stored each day in the table.

    (HH)

    00:21:45

    00:25:03

    00:23:09

    00:30:10

    Hello

    You want to use the AVG function, but that doesn't work on the number, it must convert the strings to numbers (for example, the NUMBER of days, 0-1), so get the average and then convert them to a string.

    SELECT TO_CHAR (TRUNC (SYSDATE) + AVG (TO_DATE (str, "HH24:MI:SS")

    -TRUNC (SYSDATE, 'MONTH')

    )

    , "HH24:MI:SS".

    ) AS avg_time

    FROM table_x;

    ATTENTION: the average of 23:50 to 00:50:00 will be 12:20, 00:20:00 not.  23:50 is 23 hours later at 00:50, not 1 hour earlier.

    Of course, you will get an error if even 1 of the strings is not valid.

  • How to get the average between the lines are null?

    I need to get the average between the 2 positive numbers.

    Then update the table with the average for the rows that have NULL value between 2 positive numbers.

    The average will come (78 + 89) / 2 = 83.5. Round up to 84.

    Then it will be:

    04/06/13 84

    05/06/13 84

    06/06/13 84

    Regarding the 13/06/09 and 10/06/13, these values will always be NULL.

    {code}

    create the dummy (date of tmestmp of the table

    (, maxtemp number (4,0));

    insert into dummy (tmestmp, maxtemp) values (to_date('20130601','YYYYMMDD'), 70);

    insert into dummy (tmestmp, maxtemp) values (to_date('20130602','YYYYMMDD'), 81);

    insert into dummy (tmestmp, maxtemp) values (to_date('20130603','YYYYMMDD'), 78);

    insert into dummy (tmestmp) values (to_date('20130604','YYYYMMDD'));

    insert into dummy (tmestmp) values (to_date('20130605','YYYYMMDD'));

    insert into dummy (tmestmp) values (to_date('20130606','YYYYMMDD'));

    insert into dummy (tmestmp, maxtemp) values (to_date('20130607','YYYYMMDD'), 89);

    insert into dummy (tmestmp, maxtemp) values (to_date('20130608','YYYYMMDD'), 91);

    insert into dummy (tmestmp) values (to_date('20130609','YYYYMMDD'));

    insert into dummy (tmestmp) values (to_date('20130610','YYYYMMDD'));

    {/ code}

    I need the output to look like this:

    Header 1 Header 2

    1 JUNE 13

    2 JUNE 13

    JUNE 3, 13

    JUNE 4, 13

    5 JUNE 13

    JUNE 6, 13

    JUNE 7, 13

    JUNE 8, 13

    JUNE 9, 13

    JUNE 10, 13

    70
    81
    78
    84
    84
    84
    89
    91

    null

    null

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - production

    PL/SQL Release 10.2.0.4.0 - Production

    "CORE 10.2.0.4.0 Production."

    AMT for 32-bit Windows: release 10.2.0.4.0 - Production

    NLSRTL Version 10.2.0.4.0 - Production

    Suggestions?

    TIA.

    Steve42

    Select tmestmp,

    NVL)

    maxtemp,

    round)

    (

    LAST_VALUE (maxtemp Ignore Nulls)

    (order tmestmp).

    FIRST_VALUE (maxtemp Ignore Nulls)

    (tmestmp order

    lines between the 1 suite and unlimited

    )

    ) / 2

    )

    ) maxtemp

    modeling

    /

    TMESTMP MAXTEMP
    ------------------- ----------
    01/06/2013 00:00:00 70
    02/06/2013 00:00:00 81
    03/06/2013 00:00:00 78
    04/06/2013 00:00:00 84
    05/06/2013 00:00:00 84
    06/06/2013 00:00:00 84
    07/06/2013 00:00:00 89
    08/06/2013 00:00:00 91

    TMESTMP MAXTEMP
    ------------------- ----------
    09/06/2013 00:00:00
    10/06/2013 00:00:00

    10 selected lines.

    SQL >

    SY.

  • I try to get the average of every 10 points at my table...

    I have a table of data and wish to get an output of the average of every 10 points. For example, the average of the points from 1 to 10, then the average points 11-20, then 21-30, etc.

    The challenge is that I don't know in advance how many points the sensor will collect executed because it depends on some external factors. I've attached a picture with some data made to illustrate what looks like at my table. In the example I tied, would be medium-sized (11 + 34 + 125 + 77 + 44 + 232 + 25 + 213 + 22 + 89) / 10 and (90 + 45 + 77 + 26 + 1 + 22 + 57 + 67 + 360 + 33) / 10.

    My first attempt used a structure case which found an average running and then reset whenever a multiple of 10 has been reached. However, this method is not very effective. Does anyone have ideas better?

    JarleEkanger wrote:

    How about this? Subset of the Delete table to retrieve pieces for an average and a registry change to keep the table remaining.

    It is generally not advisable to use 'delete from table' in a tight loop. Constant memory due to resizing table reallocations are probably ineffective.

    Here is a simple way to do...

    (If the number of points is not divisible by 10, the tail in excess is eliminated. You can easily change this behavior if you want.)

  • Get the average brightness of a movieclip in JPG?

    Hi, I was working on a project a few months ago that I had to warn but am finally getting back to. A major feature that I need that I wasn't able to understand before was how to measure the average brightness of an image file that is loaded as a movieclip. I remember spending hours going through the tutorials, but I couldn't make it work. Now I don't remember even what or where I read before, and I'm not wanting to read everything and still not knowing what to do.

    I want to just the simplest way possible to achieve a level of average brightness of an image, I don't like how the brightness is measured as it is only important compared to other images that will be measured the same way. Any help would be greatly appreciated, thank you.

    Back at it a year and a half later, I had to increase the number of images that are being checked, and now the inaccuracy to the reading of transparent pixels as white is too harsh. Anyone know a better way to do it?

    EDIT:

    How many times have you thought that I have this right before I actually did? In any case, here IS THE REAL SOLUTION. Less complicated than what I tried before.

    protected static void getAverageColor(image:MovieClip):Number {}

    var bmp:BitmapData = new BitmapData (image.width, image.height, true, 0x00000000);

    BMP. Draw (picture);

    BMP. Draw (image.getChildAt (0));

    var v: Vector. <> > = bmp.histogram ();

    var r: Number = 0;

    var g:Number = 0;

    var b:Number = 0;

    var a: number = 0;

    for (var i: int = 0; i<256; i++)="">

    r += I * v [0] [i] / 255;

    += g I * v [1] [i] / 255;

    b += I * v [2] [i] / 255;

    a += I * v [3] [i] / 255;

    }

    var brightness: Number = (r + g + b) /(3*a);

    BMP. Dispose();

    trace ("brightness:" + brightness);

    return of brightness;

    }

    Returns a value between 0 and 1,.5 being to halfway between pure white and pure black.

    Post edited by: xTLS

  • How can I get the price on an existing account?

    I just receive an annual subscription to creative cloud, and of course a few days later, my boss Gets an email saying that you can get it for $29.99 per month. I just bought the $ 1/27 to 49.99 a month. How can I get the discounted price?

    Hello

    In order to get the discount, you must get this new order cancellation.

    and then, you can use your promotional offer received via email.

    Please contact customer care -http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • get the average temperature over an area


    OK, I took it as an exercise fun and made the conversion from RGB in temperature for you. I extracted the color IR of your image and for each color palette, I'm looking for the closest int to color matching the color palette. This is certainly not the fastest average how to do the conversion, but perhaps a simpler.

  • SQL to get the average timestamp between 2 stamps

    I know similar question has been asked several times in several forums. Most of them deals with the recovery of interval or a difference between the timestamps in figures (hours, minutes,...) or by using PL/SQL or custom functions.

    Without using PL or custom functions, but just a sql, which is the most effective way of the timestamp of calculation which is in between 2 timestamps?

    ALTER session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS ";

    Select
    TO_DATE ('2013-12-05 04:30:20 ',' YYYY-MM-DD HH24:MI:SS') start_date,
    TO_DATE ('2013-12-06 15:00:30 ',' YYYY-MM-DD HH24:MI:SS') end_date.
    "avg_date
    Double;

    Thank you

    Srinivas - y.

    in-house dates (and tiemstamps) are just number, then you can simply add half the difference between the dates of the start_date:

    Select to_date ('2013-12-05 04:30:20 ',' YYYY-MM-DD HH24:MI:SS') start_date

    , to_date ('2013-12-06 15:00:30 ',' YYYY-MM-DD HH24:MI:SS') end_date

    , to_date ('2013-12-05 04:30:20 ',' YYYY-MM-DD HH24:MI:SS')

    + ((to_date ('2013-12-06 15:00:30 ',' YYYY-MM-JJ HH24:MI:SS')-to_date ('2013-12-05 04:30:20 ',' YYYY-MM-DD HH24:MI:SS')) / 2) date_in_the_middle))

    of the double

    START_DATE END_DATE DATE_IN_THE_MIDDLE

    ------------------- ------------------- -------------------

    2013-12-05 04:30:20-2013-12-06 15:00:30 2013-12-05 21:45:25

  • Case: View the balance of the average customer for each area code.

    Hi again together. As a C++ / VB programmer, I used by using a control specified structures like for loops and while loops and use predefined variables to solve my problems. I have a little trouble to adapt to the SQL paradigm, which really does contain a few key words and in built functions.

    I had to have some exercises to do by my tutor at the University, and I have a big enough problem with this one. I to recover the balance of the average customer of a 'customer' entity, but I have to do for each area code, not as a whole. When I look at this problem, I immediately think of loops, conditional check, a variable of integer type to control the loop and possibly a table or a vector data type to store the results. SQL is rather simple, and its simplicity is actually causing me problems, ironically.

    Here is the "Customer" entity which I am to get directions:
    CREATE TABLE CUSTOMER 
    (
                CUS_CODE            NUMERIC(6) 
                CONSTRAINT CUSTOMER_PK PRIMARY KEY,
                CUS_LNAME       varchar(15) NOT NULL,
                CUS_FNAME       varchar(15) NOT NULL,
                CUS_INITIAL     CHAR(1),
                CUS_AREACODE      VARCHAR(3) DEFAULT '02' NOT NULL CHECK(CUS_AREACODE IN ('03','07','08')),
                CUS_PHONE       VARCHAR(8) NOT NULL, 
                CUS_BALANCE     NUMERIC(9,2) DEFAULT 0.00
    );
    I was able to order the customer balances by their area code and to calculate the balances of customers on average as a whole, but as I said I had difficulties to calculate an average of customer balances exactly their area code and do it for all the codes present.

    Any help / example code would be much appreciated.

    OK, so you will understand how to get the average on all clients in SQL, not true? Something like

    SELECT AVG(cus_balance) avg_balance
      FROM customer
    

    If you want to get the average balance by another column, you simply group this column, i.e.

    SELECT cus_areacode, AVG(cus_balance) avg_balance
      FROM customer
     GROUP BY cus_areacode
    

    This essentially tells Oracle to group all data by area code before you run the aggregate function AVG on the cus_balance for each of these groups.

    Justin

  • How to get the last records of a Table

    Hey Geeks,

    I have this 'conflict '.

    I need to get the 'current balance' for each account, the newest "current_Balance".

    The table looks like this

    ACCOUNT_IDBUSINESS_TRANSACTION_IDCURRENT_BALANCETRANSACTION_AMOUNTTRANSACTION_DATE
    1 062 570238 043 51751'022-20'00031.03.2014 17:49:00.808000
    1 062 570238 042 40771'022-20'00031.03.2014 17:33:55.666000
    1 062 570238 042 36891'022-26'00031.03.2014 17:33:20.067000
    1 062 570238 041 273117'022-50,00031.03.2014 17:18:25.189000
    1 062 570238 041 174167'022-10,00031.03.2014 17:16:59.361000
    1 062 570238 038 702177'022-2'50031.03.2014 16:44:58.332000
    5 607 555238 046 7131'026-28'50031.03.2014 18:35:16.212000
    5 607 555238 040 59229'526-100,00031.03.2014 17:10:15.474000

    I need this result:

    ACCOUNT_ID CURRENT_BALANCE

    5 607 555 1'026

    1 062 570 51'022                   


    How we handle this?


    Thxs for your help


    Ineffective :-)

    SELECT Account_id

    MAX (current_balance) KEEP (DENSE_RANK LAST ORDER BY transaction_date) current_balance

    MAX (business_transaction_id) KEEP (DENSE_RANK LAST ORDER BY transaction_date) business_transaction_id

    Of account_balances

    GROUP BY account_id

    See on Oracle: clause to keep

    Concerning

    Marcus

  • Calculate the average value

    the data that I measured changed quickly, so I want to get the average value of the data

    Don't tell me to use mean.vi, I already know.

    and I got an idea that is to add data in a table every time, then the sum of all value data and take the line of result by the number of items

    but I don't know how to do this, anyone can build a simple vi to show me? Thank you

    I enclose my vi that uses mean.vi to the average value of calc, you can remove it and help in your path, thank you!

    Do not add your data in a table that grows forever. What a waste of RAM. To calculate the average, you only need to sum and N.

    Here is a simple code to accumulate the sum of the values in a shift register and divide by the number of add operations.

  • Compare and get the data in the tables (see post for details)

    I have two tables TableA and TableB. I struggle to write a query to get the dates of TableB (instead of TableA dates) where TableA dates don't coincide with the tableB (beginning and end).

    Example 1: For account A1234,.

    TableA got 2 rows 1/31/2014-3/3/2014 (which corresponds to TableB row), but TableA got another rank 31/01/2014 - 31/01/2014 that corresponds with the date of TableB Begin. In this case, I'm looking for output as below,

    Use TableB start and end date and combine number two rows from TableA for this account

    ACCOUNTTableB_BEGINTableB_ENDAMOUNT
    A123431/01/201403/03/2014100.0000000000

    Example 2: For the B7777 account.

    TableA end date aligns with the end dates of TableB for this account, in this case I want out put as,.

    Use TableB start and end date and get the amount of TableA

    ACCOUNTTableB_BEGINTableB_ENDAMOUNT
    B777705/04/201306/05/2013200.0000000000

    Example 3: On behalf of D5555,.

    Even a TableA line corresponds with TableA, there are two other rows in TableA matching start date with TableA and correspondence with the end date with TableA, in this case, that I put as,.

    Use TableB start and end date and combine number three rows from TableA for this account.

    ACCOUNTTableB_BEGINTableB_ENDAMOUNT
    D555508/08/201410/09/20141100.0000000000

    Example 4: To account E6666.

    Table corresponds to a row with TableB and no additional lines in TableA, just display the data in A table

    Tables and data:

    create table TableA
    (
      Account varchar2(10) not null,
      Begin   date not null,
      End     date not null,
      Amount  number(19,10) not null
    )
    ;
    
    
    create table TableB
    (
      Account varchar2(10) not null,
      Begin   date not null,
      End     date not null,
      Amount  number(19,10) not null
    )
    ;
    
    
    TableA Data:
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('A1234', to_date('31-01-2014', 'dd-mm-yyyy'), to_date('31-01-2014', 'dd-mm-yyyy'), 0.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('A1234', to_date('31-01-2014', 'dd-mm-yyyy'), to_date('03-03-2014', 'dd-mm-yyyy'), 100.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('B7777', to_date('18-04-2013', 'dd-mm-yyyy'), to_date('06-05-2013', 'dd-mm-yyyy'), 120.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('C6666', to_date('25-06-2014', 'dd-mm-yyyy'), to_date('08-07-2014', 'dd-mm-yyyy'), 10.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('D5555', to_date('08-08-2014', 'dd-mm-yyyy'), to_date('16-08-2014', 'dd-mm-yyyy'), 1000.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('D5555', to_date('08-08-2014', 'dd-mm-yyyy'), to_date('10-09-2014', 'dd-mm-yyyy'), 0.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('D5555', to_date('16-08-2014', 'dd-mm-yyyy'), to_date('10-09-2014', 'dd-mm-yyyy'), 100.0000000000);
    
    
    insert into tablea (ACCOUNT, BEGIN, END, AMOUNT)
    values ('E6666', to_date('01-01-2014', 'dd-mm-yyyy'), to_date('01-02-2014', 'dd-mm-yyyy'), 100.0000000000);
    
    
    TableB Data:
    
    
    insert into tableb (ACCOUNT, BEGIN, END, AMOUNT)
    values ('A1234', to_date('31-01-2014', 'dd-mm-yyyy'), to_date('03-03-2014', 'dd-mm-yyyy'), 100.0000000000);
    
    
    insert into tableb (ACCOUNT, BEGIN, END, AMOUNT)
    values ('B7777', to_date('05-04-2013', 'dd-mm-yyyy'), to_date('06-05-2013', 'dd-mm-yyyy'), 200.0000000000);
    
    
    insert into tableb (ACCOUNT, BEGIN, END, AMOUNT)
    values ('C6666', to_date('06-06-2014', 'dd-mm-yyyy'), to_date('08-07-2014', 'dd-mm-yyyy'), 10.0000000000);
    
    
    insert into tableb (ACCOUNT, BEGIN, END, AMOUNT)
    values ('D5555', to_date('08-08-2014', 'dd-mm-yyyy'), to_date('10-09-2014', 'dd-mm-yyyy'), 1100.0000000000);
    
    
    insert into tableb (ACCOUNT, BEGIN, END, AMOUNT)
    values ('E6666', to_date('01-01-2014', 'dd-mm-yyyy'), to_date('01-02-2014', 'dd-mm-yyyy'), 100.0000000000);
    
    
    
    
    SELECT A.ACCOUNT,
           A.BEGIN,
           A.END,
           A.AMOUNT,
           B.ACCOUNT,
           B.BEGIN,
           B.END,
           B.AMOUNT
      FROM TABLEA A
      LEFT JOIN TABLEB B
        ON A.ACCOUNT = B.ACCOUNT
    

    Hello

    SeshuGiri wrote:

    Hi Frank,.

    Your query/solution works very well, but I forgot to mention something in the first post...

    Please insert these additional lines and try the request again.

    TableA Additional lines:

    1. Insert into TABLEA (ACCOUNT, BEGIN, END, QUANTITY)
    2. values ('F9999', to_date (January 2, 2014 ',' dd-mm-yyyy ""), to_date (3 January 2014 ', 'dd-mm-yyyy'), 999.0000000000);
    3. Insert into TABLEA (ACCOUNT, BEGIN, END, QUANTITY)
    4. values ('A1234', to_date (March 3, 2014 ',' dd-mm-yyyy ""), to_date (4 March 2014 ', 'dd-mm-yyyy'), 999.0000000000);

    TableB Additional lines:

    1. Insert into TABLEb (ACCOUNT, BEGIN, END, QUANTITY)
    2. values ('A1234', to_date (March 3, 2014 ',' dd-mm-yyyy ""), to_date (4 March 2014 ', 'dd-mm-yyyy'), 999.0000000000);

    Question 1:

    The table has a rows for A1234 account (i.e. the time period different than the ranks for the same account)

    one is A1234 31/01/2014-03/03/2014, A1234 03/03/2014-03/04/2014

    Your query that returns two rows for A1234 account (which is what I want), but the amount is messed up.

    ACCOUNT BEGIN END TOTAL_AMOUNT
    1 A1234 31/01/2014 03/03/2014 1100
    2 A1234 03/03/2014 03/04/2014 1100

    Except:

    ACCOUNT BEGIN END TOTAL_AMOUNT
    1 A1234 31/01/2014 03/03/2014 101
    2 A1234 03/03/2014 03/04/2014 999

    Question 2:

    In some cases TableA will have an account (F9999), but the TableB don't. I can just this line by making the Left Join right join?

    I don't get the results with additional data. I get 1099 for two lines where account = 'A1234 '.  I get 1100 as the amount on the line with the account = "D5555.  You did it other changes to data?

    Except:

    ACCOUNT BEGIN END TOTAL_AMOUNT
    1 A1234 31/01/2014 03/03/2014 101
    2 A1234 03/03/2014 03/04/2014 999

    Still, I don't see why you want to 101 for the amount of the first row.  Why not 100?

    How can you know which rows from tablea should get attached to what rows from tableb, when the account is not unique?

    Maybe you want something like this:

    SELECT a.account

    b.begin

    b.end

    SUM (a.amount) AS total_amount

    FROM tablea a

    ON a.account = b.account JOIN tableb B

    AND a.begin BETWEEN b.begin

    AND b.end

    AND a.end BETWEEN b.begin

    AND b.end

    GROUP OF a.account, b.begin, b.end

    ORDER BY a.account

    ;

    but I guess just to your needs, and guessing is not a very good or reliable way to solve problems.

    Question 2:

    In some cases TableA will have an account (F9999), but the TableB don't. I can just this line by making the Left Join right join?

    Yes, it looks that you want an outer join.  What happened when you tried?  As always, post your code, the exact results you want from the given sample data, as well as an explanation of how you get these results from these data.

Maybe you are looking for