-
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.
-
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'
-
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
-
Forum Rules
|
|