Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using same column value with two conditions as different results

SezginCebiDec 17 2015 — edited Dec 17 2015

Hi all

May be it is to easy to answer what i am trying to do now but my brain has realy stop and i need your opinions. I have a account table that has values as below

AccountFeeOBJtypeunityear
11500196AA130

20

12000196AA13020
12000-196AA13020
11000-196AA13020
23000196AA13020
24500-196AA13020

So i can get debit and receiveable with two different sql query like in below but i can't get the debit and reciveable with sum in one row and sql. Please give me some opinion to go on.

Thanks

SELECT

TO_CHAR(TRIM(account))       Account_no,

  (select accountname from addressbook where addid=TO_CHAR(TRIM(account))) accountname,

sum(fee/100) debit

FROM

account   tb1

where

  obj in ('196') and tb1.type='AA' and TO_CHAR(TRIM(unit))='130'

and   year='20'  

and fee>0

group by

account

order by

account;

SELECT

TO_CHAR(TRIM(account))       Account_no,

  (select accountname from addressbook where addid=TO_CHAR(TRIM(account))) accountname,

sum(fee/100) reciveable

FROM

account   tb1

where

  obj in ('196') and tb1.type='AA' and TO_CHAR(TRIM(unit))='130'

and   year='20'  

and fee<0

group by

account

order by

account;

This post has been answered by kendenny on Dec 17 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 14 2016
Added on Dec 17 2015
6 comments
1,657 views