Results 1 to 3 of 3

Thread: Need some help with a query

  1. #1
    Join Date
    Jun 2010
    Posts
    1

    Need some help with a query

    Hello,
    I am fairly new to SQL, so any help here would be appreciated


    SELECT SUM(ABC - XYZ) AS T1
    FROM TBL1
    WHERE COND = 'Y'
    Now here is what I need to happen -
    ABC must be selected based on the condition COND = 'Y'
    AND
    XYZ must be selected based on the condition COND <> 'Y'

    Just to reiterate - I am new to SQL, so if there is any inbuilt feature that already exists that can help me with this problem, please point me in the right direction so I can do some research on it.

    Thank you.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You have to use TBL2 twice in FROM clause

    SELECT SUM(T1.ABC - T2.XYZ) AS T1
    FROM TBL1 as T1
    JOIN TBL1 as T2
    ON T1.x1 = T2.x1
    WHERE T1.COND = 'Y'
    AND T2.COND <> 'Y'

  3. #3
    Join Date
    Jul 2010
    Posts
    1
    Mixter try this out...

    SELECT SUM(decode(COND,'Y',abc,0)) - SUM(decode(COND,'Y',0,XYZ)) AS T1
    FROM TBL1

    Let me know if incorrect.

Posting Permissions

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