Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    65

    Unanswered: Totals in two columns

    Hello to all.

    I'm new to sqlplus and i'm having difficulty in achieving the following:

    I have a table with 3 columns:
    CUSTOMER_NAME (varchar2)
    VAT_TYPE (varchar2)
    AMOUNT (number)

    Depending on the vat type i would like to have a query to return:

    CUSTOMER_NAME, SUM(VAT_TYPE1), SUM(VAT_TYPE2)

    Can someone please give some help of how to achieve this?
    Thanks in advance for any kind help.
    Octavio

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    SELECT customer_name,
           sum(case 
                 when vat_type = '1' then amount
                 else null
               end) as amount_vat_1,
           sum(case 
                 when vat_type = '2' then amount
                 else null
               end) as amount_vat_2
    FROM the_table_with_no_name
    GROUP BY customer_name

  3. #3
    Join Date
    Jun 2007
    Posts
    65

    Totals in two columns

    Brilliant!
    Shammat, thanks a ton.

    Octavio

  4. #4
    Join Date
    Sep 2011
    Posts
    75
    Hello,

    You can use case statement to accomplish this....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •