Hello All,

Could any well write a query for the following scenario.

Account(table name)

No Name Amount
1 ABCD 2000.00
2 DEFG -2000.00
3 GHIJ 3000.50
4 JKLM 4000.00
5 MNOP 6000.00


O/p Should be in this format

No Name Credit Debit
1 ABCD 2000.00 0
2 DEFG 0 -2000.00
3 GHIJ 3000.50
4 JKLM 0 -4000.00
5 MNOP 6000.00 o


could any one give appropriate query for this

Thnks in Advance

Answers were Sorted based on User's Feedback



Hello All, Could any well write a query for the following scenario. Account(table name) No ..

Answer / mkumar.it

select no, name,
case amount/abs(amount) when 1 then amount else 0 end credit,
case amount/abs(amount) when -1 then amount else 0 end Debit
from account

Is This Answer Correct ?    4 Yes 0 No

Hello All, Could any well write a query for the following scenario. Account(table name) No ..

Answer / omi naik

select no, name,
decode (sign(amount),1 , amount , 0) credit,
decode (sign(amount),-1 , amount , 0) debit
from account

Is This Answer Correct ?    5 Yes 1 No

Hello All, Could any well write a query for the following scenario. Account(table name) No ..

Answer / srinu

Hi Suneel,


SELECT * FROM ACCOUNT;

NO NAME AMOUNT
----- ----- ----------
1 ABCD 2000.00
2 DEFG -2000.00
3 GHIJ 3000.00
4 JKLM -4000.00
5 MNOP 5000.00

SELECT NO,NAME,DECODE(SIGN(AMOUNT),1,TO_CHAR(AMOUNT,'9999.99'),-1,0) CREDIT,
DECODE(SIGN(AMOUNT),-1,TO_CHAR(AMOUNT,'9999.99'),1,0) DEBIT FROM ACCOUNT
/

NO NAME CREDIT DEBIT
------ ----- -------- --------
1 ABCD 2000.00 0
2 DEFG 0 -2000.00
3 GHIJ 3000.00 0
4 JKLM 0 -4000.00
5 MNOP 5000.00 0

Is This Answer Correct ?    1 Yes 0 No

Hello All, Could any well write a query for the following scenario. Account(table name) No ..

Answer / ajit nayak

select no, name,
case sign(amt) when 1 then amt else 0 end crd,
case sign(amt) when -1 then amt else 0 end debt
from account;

Is This Answer Correct ?    0 Yes 0 No

Hello All, Could any well write a query for the following scenario. Account(table name) No ..

Answer / vijay sultampur

Select No No,Name Name,Decode(Amount,Abs(Amount),Amount,0)
Credit, Decode(Amount,Abs(Amount),0,Amount) Debit
From Account;

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More SQL PLSQL Interview Questions

what is msql? : Sql dba

0 Answers  


From an Employee table, how will you display the record which has a maximum salary?

29 Answers   Cap Gemini, Exilant, Synechron,


Whate is use of MOD function in pl/sql.

3 Answers   Oracle,


can we use out parameter in a function?Give an example.

4 Answers   Logica CMG, TCS,


Mention what are different methods to trace the pl/sql code?

0 Answers  






What is assignment operator in pl sql?

0 Answers  


What are the usages of sql?

0 Answers  


What are some emotional triggers?

0 Answers  


How to run pl sql program in mysql?

0 Answers  


Explain cursor types?

0 Answers  


What is a null value?

0 Answers  


what is the difference between ereg_replace() and eregi_replace()? : Sql dba

0 Answers  


Categories