Need help pls

Experts in the morning,

I have this array with a shopping list. This is what looks like my table:
TYPE     DATE           AMT     DR_CR_IND    DEBIT_NUM      DEBIT_AMT     CREDIT_NUM     CREDIT_AMT      
2          10/1/2010    10        +                        0                       0                    0                     0                    
2          10/1/2010    20        +                        0                       0                    0                     0                    
2          10/5/2010    15        +                        0                       0                    0                     0        
2          10/9/2010    30        -                         0                       0                    0                     0 

I need to insert into the table above a row that would show the debit_num, debit_amt, credit_num, credit_amt (whatever is applicable) for each group of dates:

This is my output with the record type 1 that I need to insert.

TYPE     DATE           AMT     DR_CR_IND    DEBIT_NUM      DEBIT_AMT     CREDIT_NUM     CREDIT_AMT
2          10/1/2010    10        +                        0                     0                     0                      0
2          10/1/2010    20        +                        0                     0                     0                      0
2          10/5/2010    15        +                        0                     0                     0                      0
2          10/9/2010    30        -                         0                     0                     0                      0
1          10/1/2010                                         2                    30                     0                      0
1          10/5/2010                                         1                    15                     0                      0
1          10/9/2010                                         0                     0                     1                      30                    
How can I do this? I appreciate all help.

Thank you

Published by: user5737516 on October 26, 2010 06:48

Published by: user5737516 on October 26, 2010 06:49

Hello

Thanks for posting the sample data.
It seems that these data could produce these results:

`           TRANS     DEBIT   DEBIT  CREDIT  CREDIT
C BANK_POST  _AMT D    _NUM    _AMT    _NUM    _AMT
- --------- ----- - ------- ------- ------- -------
2 01-OCT-10    20 +       0       0       0       0
2 01-OCT-10    30 +       0       0       0       0
2 02-OCT-10    10 +       0       0       0       0
2 03-OCT-10     5 -       0       0       0       0
1 01-OCT-10               2      50       0       0
1 02-OCT-10               1      10       0       0
1 03-OCT-10               0       0       1       5

not the results you've posted. If you really want the results you've posted, explain how to get the different values.

Now that I try it, I think that a UNION would be the simplest solution:

SELECT       rec_type
,       bank_post_date
,       trans_amt
,       dr_cr_ind
,       sum_debits_num          AS debit_num
,       sum_debits_amt          AS debit_amt
,       sum_credits_num          AS credit_num
,       sum_credits_amt          AS credit_amt
FROM       purchase
       --
    UNION ALL
           --
SELECT       '1'                         AS rec_type
,       bank_post_date
,       NULL                         AS trans_amt
,       NULL                         AS dr_cr_ind
,       COUNT (NULLIF (dr_cr_ind, '-'))     AS debit_num
,       SUM ( CASE
                    WHEN  dr_cr_ind = '+'
              THEN  trans_amt
              ELSE  0
                END
           )                         AS debit_amt
,       COUNT (NULLIF (dr_cr_ind, '+'))     AS credit_num
,       SUM ( CASE
                    WHEN  dr_cr_ind = '-'
              THEN  trans_amt
              ELSE  0
                END
           )                         AS credit_amt
FROM       purchase
GROUP BY  bank_post_date
             --
ORDER BY  rec_type          DESC
,            bank_post_date
;

But, if you want to try GROUP BY:

SELECT       CASE
           WHEN  GROUPING (trans_amt) = 0
           THEN  rec_type
           ELSE  '1'
       END
,       bank_post_date
,       trans_amt,     dr_cr_ind
,       CASE
           WHEN  GROUPING (trans_amt) = 0
           THEN  SUM (sum_debits_num)
           ELSE      COUNT (NULLIF (dr_cr_ind, '-'))
       END                  AS debit_num
,       CASE
           WHEN  GROUPING (trans_amt) = 0
           THEN  SUM (sum_debits_amt)
           ELSE  SUM ( CASE
                               WHEN  dr_cr_ind = '+'
                     THEN  trans_amt
                     ELSE  0
                           END
                         )
       END                    AS debit_amt
,       CASE
           WHEN  GROUPING (trans_amt) = 0
           THEN  SUM (sum_credits_num)
           ELSE  COUNT (NULLIF (dr_cr_ind, '+'))
       END                  AS credit_num
,       CASE
           WHEN  GROUPING (trans_amt) = 0
           THEN  SUM (sum_credits_amt)
           ELSE  SUM ( CASE
                               WHEN  dr_cr_ind = '-'
                     THEN  trans_amt
                     ELSE  0
                           END
                         )
       END                    AS credit_amt
FROM       purchase
GROUP BY  GROUPING SETS ( ( rec_type,     bank_post_date
                           , trans_amt,     dr_cr_ind
                 )
               , ( rec_type,     bank_post_date
                           )
               )
ORDER BY  GROUPING (trans_amt)
,            bank_post_date
;

user5737516 wrote:... I guess I need to have a cursor and loops through each record?

No. I don't think that you need a cursor.

and make my insert?

What are you insertion?
You want to add the lines produced by the second part of the UNION over the table to purchase?
If so, use an INSERT statement with a query, the second part of the UNION that precedes.

Tags: Database

Similar Questions

  • Hey guys, ive tryied buy photoshop like a hundret times, ive typed in my information payment and everything I need, went on the button pay on the accept button but nothing happened, I need help pls passing sry for my language

    Hey guys, ive tryied buy photoshop like a hundret times, ive typed in my information payment and everything I need, went on the button pay on the accept button but nothing happened, I need help pls passing sry for my language

    Contact adobe during the time pst support by clicking here and, when available, click on "still need help," http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • New on routers... Need help pls connect with Primus d-link

    Hi all, I'm new here. I am a complete newbie to routers. I just got a Linksys WRT54GL. I managed to plug it in and it works but lost my phone service Primus IE D-link (KVD-1120).  I had going from modem to the Linksys router this router for the d-link has however led to d-link and phone does not work.

    I called Primus and after waiting on my phone cell phone $20 and 1 hour and 20 minutes later, they were no help other then to tell me that the modem must be connected directly to the D-Link and that somehow, I had to find a way to connect the Linksys router for the D-Link (only 1 WAN and 1 Ethernet port on the back (a).

    Someone along the way also told me that I had to reconfigure certain ports or open some more. I don't know how or what is the same.

    If someone is able to help, I would appreciate it so. Please guide me through it, I don't know how to find the ip address is if I need to do. (read that somewhere)

    Thanks in advance for your help and your patience

    If your Modem is already connected to the D-Link router and your phone is also connected to the D-Link router, because your D-Link router has only 1 WAN and 1 LAN Port, then you can connect the ethernet cable between the LAN Port of the D-Link router to the Internet Port on the Linksys router and configure all the settings on your Linksys router.

    Open an Internet Explorer browser on your computer (desktop) wired page. In the address bar type - 192.168.1.1 and press ENTER... Let the empty user name & password use admin lowercase...

    For wireless settings, follow these steps: -.
    Click on the Wireless tab
    -Here, select manual configuration... Wireless network mode must be mixed...
    -Provide a unique name in the name box of the wireless network (SSID) in order to differentiate your network from your network of neighbors...

    -Set the Standard - 20 MHz Radio band and change the Standard channel to 11-2, 462 GHz... Wireless SSID broadcast should be enabled and then click on save settings...
    Please take note of the name of the wireless network (SSID) because it's the network identifier...

    For wireless security: -.
    Click the sub-tab under wireless > Wireless Security...

    Change the mode of WPA wireless security, encryption, select TKIP. Password input your desired WPA key. For example, MySecretKey, this will serve as your network key whenever you connect to your wireless network. Do NOT give this key to anyone and do not forget the key.

    NOTE: The password must be more than 8 characters...

    Once you are done with the settings on your Linksys router, unplug the power to the router Linksys, D-Link router and your modem... Wait 30 seconds and turn on the power to the Modem first, wait until all lights are the lid, then connect the power supply to the router D-Link and after 30 sec connect the power supply to the Linksys router.

    Now, check if you are able to go online from the Linksys router.

  • Installation need help Pls: CS6 DVD "license revoked".

    Greetings-

    I really need a solution and am so worried, I'm sick.  Everyone here probably knows already what I discovered: there is no support phone or chat on this product. so this is my only hope for help.

    Product and system:

    Adobe CS6 Design & Web Premium DVD (original purchaser 9/2013)

    New laptop Toshiba L55 - C Windows 10. Intel core i5; 8 GB of ram; 64 bit

    Account admin & privileges

    History of the issue:

    My first installation went well past that I can remember.  In September 2014, my hard drive crashed and had to reinstall.  I remember having a problem of 'permission', called, and a living human being has solved the problem.  Unfortunately, I don't remember the exact error message, but I know that it is only installed a time (9/13) before the crash (new hd 9/14) - the same ip address, if adobe could have detected or if she was important.  I was always under the impression that we could have 2 existing facilities from a dvd.  I got the phone call on 9/14 report that the software was a reinstall on a hard drive crashed and said when I tried to install my second copy, there should be no problem.

    My laptop original has always software asset on that.  I want to be able to use two laptops (where the two copies) if possible so I can get the other oldest with me and leave a new home.  Question: The buyers are not entitled to a "free-over" when a computer falls down, such as my lost original installation + my later resettlement would not mean I'm stuck?  (I suspect that my recording software does not get connected properly as a "Reinstall due to a computer failure" at the time, I called to report - so a poorly connected two active facilities limit error the revocation.)

    It is my understanding that I have the right to have - at all times - both legal and legitimate copies for my own use, on my own computers.  Right?

    I can uninstall 'nothing' which is currently where I stayed flat with 'no' software whatsoever!  I don't have that brave.

    Error message when you install today on the new computer:

    "You have entered the serial number has been revoked." Cannot install this product. Please contact customer support. »

    Thank you in advance for your help!

    Volume License https://helpx.adobe.com/x-productkb/policy-pricing/volume-licensing-site.html

  • need help pls with query

    I need to write a report that would be altogether retained for a pay period. There will be 2 p_year and p_quarter parameters

    sample:

    pay the amount to be deducted for period emp_code
    1 XXX 2,300.00
    1 Q XXX PLACES 1 399.00

    2. IS XXX 2,300.00
    2 Q XXX 1,400.00

    There are 3 tables: calendar_table, amount_table, and deduction_codes picture

    calendar_table
    p_year
    p_payno
    p_check_date

    deduction_codes
    Code_P
    p_code_desc

    deduction_amounts
    p_year
    p_payno
    p_deduction_code
    p_amount

    Here's my query:

    SELECT c.deduction_code as deduction_code,
    d.emp_code as emp_code,
    Sum (d.employee_amt) as the amount
    Deduction_amount d, deduction_codes c
    WHERE d.year = p_year
    AND IN d.pay_period (this is the part where I need to get all the pay periods for the entered setting)
    AND d.deduction_code = c.deduction_code
    C.deduction_code GROUP, d.emp_code
    ORDER BY c.deduction_code;

    I have a few problems:
    If the user is going to happen in the YEAR and the quarter, how do I change my query? Lets say that she entered the YEAR = 2009 and QTR = Q1, whats going to happen to my request? BTW, in the table of calendar for each year there are 26 pay periods. I can use the check_date field to determine if the pay period belongs to which quarter. I don't know how to do.

    Thanks in advance!

    Published by: user5737516 on November 2, 2009 18:46

    Published by: user5737516 on November 2, 2009 18:54

    Published by: user5737516 on November 2, 2009 18:56
    Why does nobody answer?

    Good to know that we are of little help.
    So problem solved please pay points and close the debate.

    See you soon!
    Bobin

  • BlackBerry smartphones, that I need help pls

    My blackberry application blackberry Messenger and the world does not work and I deleted and downloaded, app world it dosent always impossible to download anything whatsoever, to make things worse, it dosent click on about and even less to highlight the characteristics of the world ask and also I can not click on my touch, if I tried to get my phone hang and I must remove my battery to restart... I am so worried about it... any advice pls

    Hi junola09,

    The error that you are experiencing with your address book indicates a problem with the software and it is advisable that reinstalling the software to correct this situation.

    Back up your data by using the Desktop software then follow KB11320 to reinstall the operating system (or KB19915 if you use a Mac).

    Before restoring any data when reloading the software is complete, you can access your address book to make sure that the error no longer appears and see if you are able to access BBM and App World.

    Please note that if you use BBM 7, you must use the same ID BlackBerry to restore your contacts. Ensure that you are able to access your BBID to www.blackberry.com/blackberryid

    I would like to know how the load.

  • NEED HELP PLS! Error creating CSV

    Hi all

    Can someone help me with this error?
    SQL> create or replace directory PAYROLL AS '/home/pattersj/';
    
    Directory created.
    
    SQL> GRANT READ, WRITE ON DIRECTORY PAYROLL TO PUBLIC;
    
    Grant succeeded.
    
    SQL> GRANT READ, WRITE ON DIRECTORY PAYROLL TO my_user;
    
    Grant succeeded.
    
    I login as my_user and ran this.....
    
    SQL> DECLARE
      2   File    UTL_FILE.FILE_TYPE;
      3   BEGIN
      4   File:= UTL_FILE.FOPEN('PAYROLL','a.txt','w');
      5   UTL_FILE.PUT_LINE(File,'I am writing to file');
      6   UTL_FILE.FCLOSE(File);
      7   END;
      8  /
    DECLARE
    *
    ERROR at line 1:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at line 4
    What did I miss?

    Published by: user5737516 on November 20, 2009 12:23

    Published by: user5737516 on November 20, 2009 13:07

    The file written oracle process has no unix permissions to write in ' / home/pattersj / '.

    connect to the server as the owner of the oracle software

    Touch /home/pattersj/test.txt

    I bet it will fail because of unix file permissions

    Change your directory/tmp /. It works like in unix, everyone has permissions to write in "/ tmp".

  • I need help pls

    Hello

    • I have Photoshop 9 on a CD, with 3 licenses.
    • I used 1 license on my old laptop.
    • I just bought a new laptop and there is no way to insert a CD.
    • How to install this software on my new laptop computer?
    • I have Windows 10 if it matters.

    Thank you

    Michelle

    The downloads are available through the following page: other downloads

  • Compaq mini q10_120sv: need help PASSWORD VERIFIED FAILURE fatal system error stopped CNU94880Y9

    COMPAQ MINI Q10_120SV

    FATAL ERROE ORDER CNU94880Y9 SYSTEM PASSWORD CHECK FAILED

    need help pls...

    Hello

    Enter: e9lovuu1io (3rd character is a lowercase L)

    Kind regards

    DP - K

  • photos were deleted from my phone? !!! need help urgent pls

    So I'll start from the beginning.

    So at the beginning I had 5200 pictures and everything was fine, except that I couldn't take any pictures on Snapchat. So I decided to delete some pictures. Except sometimes just deleted photos would return as 2 seconds. And sometimes I would say 5 photos selected, but I couldn't see anything selected? Or I have to press SELECT again and again.

    at least one forward a few hours and I received on my phone, except that now it says I have only 3600 pictures! I lost a few photos, especially those previously on my phone, then some of the pictures I deleted months ago as last year are back. And I have pictures on my recently removed, but not the ones I lost!

    I feel that my phone is somehow back in time or something.

    And I lost a few photos of a wedding and I regret totally stayed so much (((pls est de toute façon??))

    also, I need help using http://www.ipad-converters.org/recover-photos-from-iphone/ this type also.

    Hello

    When you recharge an iPhone / iPad, it will be saved up to iCloud on wifi you

    Restore the original configuration.

    When configuring back it will ask you if you want to use iCloud backup say yes

    Use the backup of a time where you had all your photos.

    See you soon

    Brian

  • Pls I need help to reset my bios of my computer compaq mini CQ10

    Pls I need help to reset my bios of my computer compaq mini CQ10-130se

    error fatal problem with CNU0014WZF

    TNX!

    Hello

    Please try:

    For CNU0014WZF (two zeros after U).

    e9l113vd08 (all lowercase, 3rd tank is a tiny l)

    Kind regards.

  • Pls I need help to reset my bios of my computer compaq mini CQ10. The error code is CNU9513HB4

    Pls I need help to reset my bios of my computer compaq mini CQ10. The error code is[personal information deleted]

    Hello

    Please try (all lower case):

    e9loq3fzpv (3rd tank is a tiny l).

    Kind regards.

  • Hello, PLS I need help I can't install Windows live messenger

    Hello PLS I need help I can't install Windows live messenger pls help me so when I try to download and then I see a message could not install programs windovs use update to download the latest version of Installaer Windows and then try again: PLIS HELP ME OUT coz my endlish isn't God can u send me pls e direkt link for this problem of fixit pls * address email is removed from the privacy * I have instalet Sistem mikrosoft version 2002 service pack 2 XP Prefesional my any is XP I I 2.67 GHz 1.24 GB of Ram i thank you very much for your help

    Hi valeria2012,

    You should be able to manually download KB2360937 from here:

    http://www.Microsoft.com/en-US/Download/details.aspx?displaylang=en&ID=17751

    Also, you can take a look at the article below for troubleshooting on your particular error:

    http://support.Microsoft.com/kb/956703

    I hope this helps!

  • I don't see the icon of mail in the Panel, I need this to configure outlook express help pls

    I don't see the icon of mail in the Panel, I need this to configure outlook express help pls

    Hello

    1. are you referring to Windows mail or Outlook Express?

    2 have you made changes on the computer before this problem?

    3 What is a 32-bit or a 64-bit operating system?

    Try the next method and check if it helps.

    Method 1:

    Step 1:

    Change the setting from Control Panel and check if that helps.

    a. Click Start, then select Control Panel

    b. click on additional Options

    c. Select view 32-bit Control Panel items and click on Mail and check if that helps.

    Step 2:

    Change the display panel and check if it helps

    a. go to control panel,
    b. click view classic icons

    See also:

    http://Windows.Microsoft.com/en-us/Windows-Vista/where-is-Outlook-Express

    http://Windows.Microsoft.com/en-us/Windows-Vista/import-messages-into-Windows-mail-from-Outlook-Express

  • I NEED HELP Please im having a problem to forget my password and when I plug it it says its locked with a password he try to put the itunes thing but

    NEED HELP Please im having a problem to forget my password and when I plug it it says its locked with a password he tried to put the itunes thing but it says enter password I put in what I rember, then said lokced for five minutes help me pls

    Without knowing the password for your iPhone, there is no way to unlock it, bring even you to the Genius Bar. If you continue to enter the wrong password, you will be locked out of your iPhone, and your data will be unaccessable.

Maybe you are looking for