Calculate RATIO_TO_REPORT by payment method

Hi, I want to output a report is I hope that by the analytical function I think but don't know how. Represents Account_payment entity money paid by customers per day and have a mode of payment is paid. I want to ration to report total first monthly would be TO_CHAR (DATE, ' MON-YYYY "") and cumulative up to a month and calculate the RATION_TO_REPORT based on the rollup for a different payment type. I have an example I faked in excel hopfully example explain better what I want to achieve. Thank you

WITH ACCOUNT_PAYMENT AS
( SELECT  157 AS account_id, TO_DATE('20-JAN-2011','DD-MON-YYYY') AS payment_date, 150.50 as payment_amount, 'DIRECT-DEBIT' AS PAYMENT_TYPE FROM DUAL UNION
  SELECT 158,TO_DATE('20-JAN-2011','DD-MON-YYYY') ,180.50,'CHEQUE'         FROM DUAL UNION
  SELECT 159,TO_DATE('08-FEB-2011','DD-MON-YYYY') ,190.50,'IVR'         FROM DUAL UNION
  SELECT 168, TO_DATE('20-FEB-2011','DD-MON-YYYY') ,1290.50,'DIRECT-DEBIT'         FROM DUAL UNION
  SELECT 16888, TO_DATE('20-APR-2011','DD-MON-YYYY'),2090.50,'CHEQUE'         FROM DUAL UNION
  SELECT 2168, TO_DATE('21-APR-2011','DD-MON-YYYY') ,5090.50,'DIRECT-DEBIT'         FROM DUAL UNION
  SELECT 168, TO_DATE('2-MAY-2011','DD-MON-YYYY') ,7190.50,'IVR'         FROM DUAL UNION 
  SELECT 02168, TO_DATE('03-MAY-2011','DD-MON-YYYY') ,7190.50,'IVR'         FROM DUAL 
), SUMMARY_FOR_RATION_TO_REPORT AS 
(
SELECT TO_CHAR(payment_date,'MON-YYYY') as "Month",
               PAYMENT_TYPE,
              SUM(payment_amount) TOTAL_PAYMENT   
 FROM ACCOUNT_PAYMENT 
 GROUP BY TO_CHAR(payment_date,'MON-YYYY'),               PAYMENT_TYPE 
 )SELECT 
        "Month", 
        payment_type, 
        SUM(TOTAL_PAYMENT) AS TOT_PAYMENT
 FROM SUMMARY_FOR_RATION_TO_REPORT
 GROUP BY ROLLUP( "Month", payment_type) 
 ORDER BY 1 ASC; 
Ideal output
Month     PAYMENT_TYPE     TOT_PAYMENT     PCT     
Apr-11     CHEQUE          2090.5          29%     
Apr-11     DIRECT-DEBIT     5090.5          71%     
Apr-11               7181          100%     
Feb-11     DIRECT-DEBIT     1290.5          87%     
Feb-11     IVR          190.5          13%     
Feb-11               1481          100%     
Jan-11     CHEQUE          180.5          55%     
Jan-11     DIRECT-DEBIT     150.5          45%     
Jan-11               331          100%     
May-11     IVR          14381          100%     
May-11               14381               
               23374
Edited by: ricard888 09/02/2012 17:29

Edited by: ricard888 09/02/2012 17:36

Edited by: ricard888 09/02/2012 19:01

Hello

ricard888 wrote:
Hi Frank, e.g. conversion of the months of lines to the column.

PAYMENT_METHOD     1/01/2011     1/02/2011     1/03/2011
IVR           7.38            7.57            8.13
DIRECT-DEBIT      19.36            17.16            19.69 

Yes, you can do it.
If you know, when you write the query, what months will be included, so you can do something like

SELECT    payment_method
,         SUM (CASE WHEN  month = DATE '2011-01-01' THEN payment_amount END)   AS "1/01/2011"
,         SUM (CASE WHEN  month = DATE '2011-02-01' THEN payment_amount END)   AS "1/02/2011"
,         SUM (CASE WHEN  month = DATE '2011-03-01' THEN payment_amount END)   AS "1/03/2011"
...
GROUP BY  payment_method  -- do NOT include month here

in the main query, where the month is TRUNC (payment_date, 'MONTH'), as before.

If the month will change, but you know there will always be 3 of them, then you can use the ROW_NUMBER analytic (or maybe DENSE_RANK) work for numbers (1 for the older month, 2 for the average month and 3 to the most recent) and use these numbers to months instead of DATEs in the pivot , like this:

SELECT    payment_method
,         SUM (CASE WHEN  month_num = 1 THEN payment_amount END)   AS month_1
,         SUM (CASE WHEN  month_num = 2 THEN payment_amount END)   AS month_2
,         SUM (CASE WHEN  month_num = 3 THEN payment_amount END)   AS month_3
...
GROUP BY  payment_method  -- do NOT include month_num here

To replace the generic column names (for example, month_1) with meaningful names (for example, "01/01/2011") requires dynamic SQL.

If you don't know how many months will be included, see this thread:
Re: County report and the sum of the number of rows by multiple columns

Do you still want the pct column? If so, show how you want it to appear in the output.

Tags: Database

Similar Questions

  • Hey, need help. I get this in my iPhone that 'there is a problem of billing with a previous purchase. Please update your payment method"in any way I can remove my visa card from iTunes

    Hey, need help. I get this in my iPhone that 'there is a problem of billing with a previous purchase. Please update your payment method"anyway I can remove my visa card from iTunes?

    You must pay your debt first.

  • Your payment method has been denied. Please enter a different payment method

    I can't make the purchase

    How are you trying to pay? Are you sure it is a valid method for your country? You enter a payment method for the country where you reside? You cannot use the iTunes Store in a different country.

    Payment methods, you can use in the iTunes Store, App Store and iBooks Store - https://support.apple.com/HT202631

  • My payment method is declined is. What should I do?

    MY payment method is declined is. What should do?

    You have another card you could try?

    If you try to use a debit card, then maybe that's why it is not accepted, not all always seem to work (and would not be allowed at all in some countries).

    A card having a chance to be accepted it must be registered with the same name and address (including the format and spacing etc) that you have on your iTunes account and have been issued by a bank in the country where you are (and, therefore, the country that sits on your iTunes account).

  • Why can I not select a different valid payment method when family shares the payment method is not valid?

    I am part of a family sharing account as my wife configuration. She chose the payment method is not valid, but I have another method of payment which is valid, but when I try to make a purchase, I thought that the paymemt on the part of the family is not valid. With my account, I should be able to choose an another valid payment method which is gone on the record and associated. And the organiser of the method of payment for the account on the part of the family should be notified so that they can solve the problem. Please Apple, improve the customer experience, so I can choose the valid payment option and make my purchase (a free app in this case).

    FYI, you talk about other users on these forums, not support nor Apple iTunes.

    With the family sharing only the map of the organizer can be used for purchases, or if you have a balance on your account that will be used - you can not use a card on your account for purchases: purchase family and payments - Apple Support

    If you want to leave a comment for Apple: http://www.apple.com/feedback/

  • "Your payment method has been declined. Please enter a different payment meth

    So I can't update and upload anything again, and I don't know why. the "Please sign see billing...» «And I continue and sign up, and then when I'm finished it is said that «your payment method has been denied please choose another method of payming.» but I only have visa and they do not accept visa. So now I can not download or even update all apps. Even the free. And I am also updating, I am on ios 9.2. And I don't know why. Please just solve this problem I want to upload, download and update the applications again. I didn't know what happened.

    Hello

    Just checked my card & Visa & it works great.

    Go down from page apple itunes homepage click on ID on that go to payments

    Check payment details & the number 3 digits on back of the card.

    See you soon

    Brian

  • Is it possible to add a person to my family membership of music Apple without sharing the payment method?

    Is it possible to add a person to my family membership of music Apple without sharing the payment method?

    N ° once that you add to the sharing of the family, they will be required to use CC of the organizer of the family to pay for purchases.

  • Cannot add a Microsoft Account, country = Australia payment method

    My billing address is in Australia.

    However, I can't add a mode of payment by credit card, because the input screen allows only the addresses in the USA.

    I confirmed that my PC is registered for "Australia" region and have restarted the PC.

    Why can't I add a nedw payment method.


    Please contact billing for that matter https://support.microsoft.com/en-us/gp/customer-service-phone-numbers/en-us?wa=wsignin1.0
  • Cannot add payment method

    Victorinox original title: AppStore purchases

    I can't buy an app, it asks me to add a payment method but it will default the counrty in the USA and I then saw the Canada he used to accept my address?  My microsoft account there a means of payment is entered and my correct address, but the info doesn't seem to pull through the app store

    Hello ScottWells925,

    You should check this: type of screen to the Start area. On the right side, select settings, and then on the left side, select the region. Select the location tab if it is not set for the Canada it changing in Canada, then select apply, then OK at the bottom. Restart your device RT, go to the app Store, I hope that the issue will be resolved.

  • Are there fees for adding a payment method for my Microsoft Account?

    If I add a new payment method will I will I be charged any amount or be required to make a purchase?

    N ° you can add a new payment method and can make purchases at any time in the future. Microsoft doesn't charge you added a mode of payment to your Microsoft Account. However, we may hold an equivalent amount of $1 on your credit card. This expectation that will be released in 1 to 5 days from the date where you saved your credit card with Windows Store.  (Time varies depending on each bank's rules).  If you add another mode of payment such as PayPal, there is no authorization charge.

  • Unable to add payment method?

    I tried to buy an app from the store, but it tells me that I must first add a payment method. That's fine, except when I try to do, I click on the 'Add payment' button, and nothing happens. Is it possible that I can add my payment information?

    Hello

    Thanks for posting in the Microsoft Community.

    According to the description, you are unable to complete the payment method to buy the app. am I right?

    Follow the steps to reset the Windows Store cache.

    a. type the Windows key + X on the keyboard.
    b. Select prompt (Admin)
    c. type wsreset.exe
     

    Please report if you are still having the problem. I will be happy to provide you with additional options.

  • Cannot add the payment method that I can't change the country in Windows store information field.

    Hello

    I want to buy an app in the store windows using my credit card.  I found the section where I can add payment options.  It's all good and Nice, the only problem is that I can't change the country for when I'm in my credit card information.  It is a static field set to the United States.  Fill in the information because I live in the Canada.  If you can let me know if this is something I could do wrong.

    LinkHero

    I discovered what the problem is.  I don't know when this happens or what it is connected to.  As far as I know is if you go in '-> Panel-> clock, language and region change the location ' then change the "location:" in your country.  You should be able to add the payment method.

    Now, it worked for me and I'm guessing that this setting is set by default to the States.  Don't know why it is not requested in the installation where you live, but I guess they have there reasons.
  • We cannot add your payment method. Please do not forget that it has not been added...

    I can't renew my subscription for at least 1 month. My payment method previous balance, but microsoft does not take any money from him. So, I try to delete it and add it again. But microsoft does not delete it (I think that there must always be a payment). How can I make my payment due to this procedure of nonsense? Must I have a loan a different credit card and add it to the system then delete mine and then add it again mine and then delete the other credit card? What is your problem guys?

    Hi Hayletbisi,

    Thanks for posting your query on the Microsoft Community.

    I understand the inconvenience that you face on the billing screen. In order to diagnose and resolve the issue, I would say that you try the following and check if they are useful.

    Method 1:

    You can check if the region is correct. Refer to the following steps.

    1. Type 'region' on the start screen. Click on 'settings', and then press ENTER.
    2. Under the "Format" tab, select "English (United Kingdom).
    3. Click on 'Preferences of languages' > 'add language' and add 'your language'.
    4. One time added, select it and click "move up" to make it the first language. Close the window of the language.
    5. In the 'region' window, click on "other settings" and check if the values are the same.
    6. Click on the "location" tab and change the location of the home to "your country" and then click OK.

    You can check the link for more information.

    Add or change your payment method for the Windows store

    http://Windows.Microsoft.com/en-us/Windows-8/Add-Edit-payment-method-Windows-store

    Method 2:

    If the problem persists, or you have any additional billing questions related to the Windows store, I would have you go to the Microsoft support website, select the category of your question, and then choose a support option. One of our support agents will be answering your questions related billing and help you solve the problem.

    Hope this information is useful. Let us know if you need more help, we will be happy to help you.

  • "Can't set the payment method.

    I'm unable to set up a payment account on Windows 8 for the store.  When I try to make a purchase it say ' there was one creating error your payment method.  It gives me options to retry and cancel, try reload the same page again.  Skip the advice of another question I tried the prompt command and typing wsreset.exe without result.

    Hello

    Thank you for your response.

    I suggest you to chat with open answer

    http://answerdesk.microsoftstore.com/

    If you need help with Windows, thanks for posting. We will be happy to help you.

  • Change country/region for the payment method setting

    I'm trying to set up my Windows App Store billing payment method, but my country appears as in the United States, the problem is that I'm in the Canada.  This field does not seem to be available for editing and so I can't set up a method of payment.  How can I change this?

    Change your location to the Canada in the region in the Panel, if it is not set. There is another parameter in the PC settings, privacy that allows applications to determine your location. Turn off if your area has already been set to the Canada in the Panel. Some errors have been reported at the location determination.

    If you need help with this contact Microsoft store.

Maybe you are looking for

  • AppleScript to control the Apple TV?

    I thought I could do something like: say application "iTunes." say AirPlay device "Apple TV 4th gen. pause end say end say .. .but apparently that doesn't work. The script runs without error, but nothing happens on the Apple TV. Is there another way

  • List of deleted files on Windows vista

    Hello I accidentally deleted music files and emptied the Recycle Bin... How can I find a list of the names of files that have been deleted by mistake? I don't need to recover the files, just to know what files have been removed from my pc. Thank you

  • I can't put my Dell Inspiron 5423 back to the factory setting after the upgrade to Windows 8.1

    Dear Sir/Madam, I upgraded my laptop Windows 8.1 yesterday and he had some compatibility problems with some applications. I want to restore it before the upgrade but cannot, then I run the Dell backup / recovery of value factory setting, but has no s

  • Lexmark 4500 custom print.on printer screen says: cartridge error...

    have uninstalled the printer, reinstalled... the connections... nothing is new working.put ink in about 3 weeks ago... just maybe 2-3 pages... maybe the printer is shot... Thanks for your suggestions...

  • HFM hierarchy

    HelloI'm new to HFM. Can you please let me know if its possible to see all hierarchies in HFM similar to essbase outline or planning hierarchies. It is also possible to extract the HFM hierarchies.Thanks for your time on this.