Enter the first rows and put him in column wise

Here are two dump, I want to take the first 2 rows in ascending order of from_date and make wise column, the first line label first_charge and second row as second_charge. AND lay rows of 3 are not necessary.

1st bucket 5 columns are my entry,

2nd dumpster 3 columns ARE my desired output.

I tried the rank function, but can someone please confirm that this is a way to do this for all the accounts table

Script (table and data) to dump 1 is at the bottom of the message.

Anyone can help with this problem - thanks.
--FIRST DUMP
ACCOUNT_ID     CHARGE_AMT     CHARGE_DATE     FROM_DATE     THRU_DATE
212855740     14.52          5/04/2012     14/03/2012     31/03/2012
212855740     25          5/04/2012     1/04/2012     30/04/2012
212855740     25          5/05/2012     1/05/2012     31/05/2012
212855740     25          5/06/2012     1/06/2012     30/06/2012
212855740     25          5/07/2012     1/07/2012     31/07/2012
212855740     25          5/08/2012     1/08/2012     31/08/2012
212855740     25          5/09/2012     1/09/2012     30/09/2012
212855740     25          5/10/2012     1/10/2012     31/10/2012
212855740     25          5/11/2012     1/11/2012     30/11/2012
                    
--DESIRED DUMP                    
ACCOUNT_ID     PRO_CHARGE     MONTHLY_CHARGE          
212855740     14.52          25          
     
WITH CHARGE_TABLE_QUERY
     AS (SELECT account_id,
                charge_amt,
                charge_date,
                from_date,
                thru_date,
                ROW_NUMBER ()
                   OVER (PARTITION BY account_id ORDER BY from_Date)
                   row_num
           FROM my_tbl)
  SELECT account_id,
         MAX (CASE WHEN ROW_NUM = 1 THEN CHARGE_AMT ELSE 0 END) PRO_CHARGE,
         MAX (CASE WHEN ROW_NUM = 2 THEN CHARGE_AMT ELSE 0 END) MONTHLY_CHARGE
    FROM CHARGE_TABLE_QUERY q
   WHERE row_num IN (1, 2)
GROUP BY account_id;

ricard888 wrote:
What happens if a new account where there is still no second indictment. I have null or 0 in the monthly_charge.

You could test easily. In any case, it will work without modification in the code

insert into my_table
select 1,50,CHARGE_DATE,FROM_DATE,THRU_DATE
from my_table
where rownum = 1;

1 rows inserted.

with CHARGE_TABLE_QUERY as
(
  select account_id,charge_amt,
         ROW_NUMBER ()
            OVER (PARTITION BY account_id ORDER BY from_Date)  rn,
         lead(charge_amt)
           OVER (PARTITION BY account_id ORDER BY from_Date) MONTHLY_CHARGE
  from my_table
 )
select account_id,charge_amt pro_charge,monthly_charge
from CHARGE_TABLE_QUERY
where rn = 1;

ACCOUNT_ID PRO_CHARGE MONTHLY_CHARGE
---------- ---------- --------------
         1         50
 212855740      14.52             25 

Tags: Database

Similar Questions

  • first row and all rest in descending order query

    Hi all

    If I have a table with two columns

    ID country_name

    1 England

    2 China

    3 India
    4 the Japan
    5 canada
    so if I want to output where id 3 comes on the first row and all rest in descending order. What will be the query?


    Thank you


    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    ...

    ORDER BY decode(id,3,1,2), id desc

    HTH

  • I used "msconfig, in an attempt to speed up my laptop. I did something wrong and I can not enter the first 13 items, only the trial version. I'm on vacation and he would like you could give me a temporary serial number fo three weeks please. Phil M

    I used "msconfig, in an attempt to speed up my laptop. I did something wrong and I can not enter the first 13 items, only the trial version. I'm on vacation and he would like you could give me a temporary serial number three weeks please. Phil McMillan

    To the link below, click on the still need help? the option in the blue box below and choose the option to chat...
    Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache.  If it fails to connect, try to use another browser.

    Serial number and activation support (non - CC) chat
    http://helpx.Adobe.com/x-productkb/global/Service1.html ( http://adobe.ly/1aYjbSC )

  • Problem with the removal of the first row of the table

    Hi all

    I have a problem with my forms with tables where I have buttons to add or remove rows from the table. Adding the lines works fine but deleting lines has a problem when deleting the first row. Example: Here is a table with two rows where column 1 has the add and remove buttons and column 2 user imput that looks like this:

    Column 1
    Column 2
    Add and remove buttons hererank 1
    Add and remove buttons hererank 2
    Add and remove buttons hererank 3

    If the user deletes line 2 the table looks like which is correct:

    Column 1
    Column 2
    Add and remove buttons hererank 1
    Add and remove buttons hererank 3

    If the user deletes line 1 then the table looks like which is false since the ranks 2 and 3 should be left:

    Column 1
    Column 2
    Add and remove buttons hererank 1
    Add and remove buttons hererank 3

    The code is pretty simple:

    Table3.row2.instanceManager.addInstance (1); for the click event of the button Add line

    Table3.row2.instanceManager.removeInstance (1); for the click event of the button Delete line

    What I am doing wrong?

    Thanks in advance!

    Al

    The expression will be based on your structure... done .This refers to the current object, parent refers to the container parent of this object and index is the index of this object. So watching your hierarchy and from the key, you will need this.parent to join the line subform is it in (usually it is th esubform that repeats). If it's in a subform, you will need to add another parent. Continue on this road until you get to the repeating subform and then ask its index. Your expression might look like this.parent.parent.parent.index. Using this.index, you find the instance of the button object and there are just people and that's why you always get 0.

    Make sense?

    BTW your form is attached not... so I can't check what you should put it.

    Paul

  • How to freeze the first row in Microsoft Excel 2008 for MAC (worms. 12.3.6.)?

    Hello world

    I need to set the first row of a table in Excel 2008 for Mac. I know it should by a button, but don ' t have probably, or is hidden somewhere I checked the point of view, the tools and all the menu, I didn't find, y at - he someone to help me? Thank you

    Make sure you are in Normal mode, not Page view

    Go to the window in the menu bar and select freeze the panes

    Then you should be able to scroll through the sheet with line 1 has left in place.

    If you need for example three rows frozen, go to the fourth line and select freeze the panes.

    Then you should be able to scroll through the sheet with lines 1 to 3 from left in place.

  • How to make a text field to accept a capital letter has or a number in the position of the first character and only the numbers after that?

    Hi all

    We have a text field in one of our screen in our mobile app. Currently the user can enter alpha numeric characters in this text field.

    It is now that this field should accept a capital letter A or a number in the position of the first character and only the numbers after that.

    Could someone let us know how to do this?

    Thank you.

    Or, how about the substitution of this abstract method in textFilter?

    public boolean validate(character char,
                            AbstractString text
    int position)

  • How to ignore the first row of the table when VO is used as a dvt:pieGraph?

    Hello

    I have a VO object read-only. I use this VO datacontrol object to display a table and pieGraph to my jspx page. When removed from the datacontrol as a pieGraph in page jspx, it gives the graph to 50% of the total (which is the first line) and all other lines at 50%. Here, my problem is that the first line of a column in the table is total of all other lines in this column. Now, I have to show the pieGraph with slices of all lines except the first row.  Is there a way I can do this without using programmatically. Or any other simple solution for program help. Help, please.

    Thank you

    Ashok Laura.

    Hello

    Assuming that we have a table that displays the details of the Department. We will build a dynamic pie chart to display the employee details for departments that are displaced from the Department table. Please check below blog.

    https://blogs.Oracle.com/ADF/entry/dynamic_pie_graph_generation_by

    Thank you

    Amey

  • How can I set the first row is 0, depending on the text box

    How can I set the first row is 0, according to the text box selected_text_to_inlineobj.jsx


    https://gist.github.com/milligramme/9368861@

    Try this,

    function boooxed (object_style_name) {
      if (app.selection.length !== 1) return
      var doc = app.documents[0];
      var sel = doc.selection[0];
      if ('baseline' in sel) {
        var bx = sel.insertionPoints[0].textFrames.add();
        bx.appliedObjectStyle = doc.objectStyles.item(object_style_name);
        bx.geometricBounds = [0,0,5,30];
        sel.duplicate(LocationOptions.AT_END, bx.parentStory);
        bx.insertionPoints[0].firstLineIndent=0;
        bx.fit(FitOptions.FRAME_TO_CONTENT);
        if (sel.contents.length) sel.remove();
      }
    };
    
    var object_style_name = "AAA"; //set anchored object settings, textframe preferences, and more
    boooxed(object_style_name);
    

    Vandy

  • How to get the sum of the first row in the previous row?

    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line. Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Hello

    kamranpathan wrote:
    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line.

    If you do not explicitly give a windowing clause, then you get the default windowing clause you indicated.
    If you want another clause of windowing, ionclude in the analytic function call.

    Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Yes. The correct syntax for "Previous rank" is «PREVIOUS 1»

    ...  ROWS BETWEEN  UNBOUNDED PRECEDING
                AND        1          PRECEDING
    

    For more information, search for "Analytic Functions" in the manual of the SQL language:
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm#sthref917

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will find the answers better faster if you always provide this information whenever you post a question.

    Published by: Frank Kulash, Sep 17, 2011 17:04
    I just saw Etbin responses.
    As usual, Etbin has a good point. If the column that you are basically cannot be NULL, then it is probably easier to subtract the total current line and use the default windowing clause.
    Even if it can be null, you find may be easier to use this approach.

  • The letters on my keyboard on the screen are passed. that is the A is now in the first row of letters, the M is in the middle line. How can I change?

    The letters on my keyboard on the screen are passed. that is the A is now in the first row of letters, the M is in the middle line. How can I change? I don't know how he has changed as a first step.

    Try the settings > General > keyboard > English > typing on the QWERTY keyboard. -AJ

  • comes to connect in iCloud for the first time and to synchronize my calendars etc I noticed it all disappeared.  How can I restore them?

    comes to connect in iCloud for the first time and to synchronize my calendars etc I noticed it all disappeared.  How can I restore them?

    They run iCloud.com? You have them on a computer?

  • upgrade to windows 10, cannot open itunes, it opened the first time, and imported all my songs, but does not open a second time, get the error that the path is not correct and file not found

    upgrade to windows 10, cannot open itunes, it opened the first time, and imported all my songs, but does not open a second time, get the error that the path is not correct and file not found

    Try to repair the security permissions for iTunes for Windows and the empty/corrupted after upgrade/crash iTunes library.

    TT2

  • When you enter the user name and password in Windows Mail I get the following error: Server error: 0x800CCC90, error number: 0x800CCC92.

    Difficulties of username and password.

    In Windows Mail I suddenly wonder for the user name and password.  I fill them but receive no mail from mu.  I get the message:

    Account: 'pophost1.classicfm.net', server: 'pophost1.classicfm.net', Protocol: POP3, server response: '-ERR failed the connection. ', Port: 110, secure (SSL): no, Server error: 0x800CCC90, error number: 0x800CCC92.
    Please can you help me?

    Hello

    ·         Were there any changes to the computer, lately?

    Method 1:

    (a) start the Windows Messaging mail client.

    (b) click on 'Tools' from the main menu and choose "accounts".

    (c) a pop up will appear showing you all the email accounts in Windows Mail. Select the one that gives you the error and then click on the button 'Properties'.

    (d) another window pop up displays all parameters associated with this account.

    (e) under the "servers" tab check the 'e-mail username' and 'password'. One of them would certainly incorrect which translates the ID of Windows Mail error 0x800CCC92

    (f) to avoid having to enter the user name and password each time, check the box in front of "Remember password".

    (g) once you make the appropriate changes, click on the button 'apply' then 'OK'. Close the other pop-up window

    Method 2: Remove the existing from Windows mail email account and create a new one following the link provided below.

    http://Windows.Microsoft.com/en-us/Windows-Vista/add-or-remove-a-Windows-mail-account

    Reference:

    http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-problems-with-Windows-Mail

  • Everytime I open my Windows Live email account I asks me to enter the user name and password and I see an 0x8000CC17 error message

    Whenever I open my email account, I asks me to enter the user name and password and I see an 0x8000CC17 error message. Please can you offer any advice. Thank you

    * original title - Hello, I am a user of Windows Vista and my email account is windows mail *.

    Hi Petersanswers,

    Thanks for posting your question in the Microsoft answers Forum.  For information about Windows Live Mail, please visit the following link:

    http://windowslivehelp.com/forums.aspx?ProductID=15

    Thank you!

  • When you get a retailer to re - install Vista are you able to burn a copy of Vista as when he was the first new and turned on for the first time?

    Hello and Merry Christmas to all. Sorry its been a while that I had time to be on the forum, (family illness) Anywho my daughter had dropped her Lenovo and although we went through every conceiveable options to retrieve and detaches from the dreaded "black screen" we couldn't. We had the chance to recover his files before he died forever! That was the good part... I had to resume at Tiger Direct, where they installed a new concert 320 H/D and re-installed Vista. Because she graduated she had two of the residence and turned my basement into a hoarders paradise, lol point being that she has no idea where his original disk is so I contacted Lenovo who assured me that they would send me a copy of Vista (how naïve of me) they me sent recovery disc (two games not less and it took more than a month!) that I discovered after the fact that I could have burned my own through Neo-Smart...

    There is one thing that still bothers me and that's when we first pulled his new Lap Top for the first time and installed Vista I remembered that the very last paragraph said to make your own copy of the o/s before your done... what was not done! Is it still possible to make a copy of its operating system now? If Yes, how would go about this, if I wait for her to do it, it will not! She was lucky that I was able to use a slave to its hard disk of my XP Sata-IDE cable and get its files on the drive before it me locked. It has an external H/D as most of the people who do not know how to change their scores on the top of their Tower and get the full use out of them as desk top users do.

    As aways thanks for the fellow forumer for your time and trouble and any help is appreciated.

    Tiggerer

    Hello and Merry Christmas to all. Sorry its been a while that I had time to be on the forum, (family illness) Anywho my daughter had dropped her Lenovo and although we went through every conceiveable options to retrieve and detaches from the dreaded "black screen" we couldn't. We had the chance to recover his files before he died forever! That was the good part... I had to resume at Tiger Direct, where they installed a new concert 320 H/D and re-installed Vista. Because she graduated she had two of the residence and turned my basement into a hoarders paradise, lol point being that she has no idea where his original disk is so I contacted Lenovo who assured me that they would send me a copy of Vista (how naïve of me) they me sent recovery disc (two games not less and it took more than a month!) that I discovered after the fact that I could have burned my own through Neo-Smart...

    There is one thing that still bothers me and that's when we first pulled his new Lap Top for the first time and installed Vista I remembered that the very last paragraph said to make your own copy of the o/s before your done... what was not done! Is it still possible to make a copy of its operating system now? If Yes, how would go about this, if I wait for her to do it, it will not! She was lucky that I was able to use a slave to its hard disk of my XP Sata-IDE cable and get its files on the drive before it me locked. It has an external H/D as most of the people who do not know how to change their scores on the top of their Tower and get the full use out of them as desk top users do.

    As aways thanks for the fellow forumer for your time and trouble and any help is appreciated.

    Tiggerer

    Hey tiggerer

    NeoSmart is software startup repair not a recovery disk to reinstall vista

    and once you have replaced your hard disk you have lost the ability to do the recovery disk from the recovery partition that may have been defective hard disk

    and it depends on your version of vista as to whether you can now make a backup complete pc using microsoft software

    you need vista business or vista ultimate to backup full pc

    read information from microsoft about it at the link below microsoft

    http://Windows.Microsoft.com/en-us/Windows-Vista/back-up-your-programs-system-settings-and-files

    If you have not these versions vista expect from lenovo recovery disks be delivered or buy a third party program to do a full backup pc

    one of these programs is the true picture in the link below

    http://www.Acronis.com/

    have a happy holiday season

    Walter, the time zone traveller

Maybe you are looking for