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
Suneel Reddy

Answers were Sorted based on User's Feedback



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

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 ?    10 Yes 0 No

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

Answer / saravana sundar

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

Is This Answer Correct ?    5 Yes 0 No

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

Answer / ehtesham malik

Select no,name, 0 Debit, amount Credit
from temp
where amount >0
union
Select no,name, amount Debit, 0 Credit
from temp
where amount < 0

Is This Answer Correct ?    2 Yes 0 No

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

Answer / shailesh

SELECT NO,NAME,DECODE(GREATEST
(AMOUNT,0),0,AMOUNT,0) "DEBIT",DECODE(GREATEST
(AMOUNT,0),0,0,AMOUNT) "CREDIT" FROM ACCOUNT

Is This Answer Correct ?    1 Yes 0 No

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

Answer / john bershan

@ mkumar.it

the query which you have posted will work if the amount
value is greater than zero and will not work in the case
when the vale s zero as it will throw divisor is equal to
zero.please check it.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / suresh kumar somayajula

Select No,Name,to_char(Sal,'$9999.99') amount from emp;

Is This Answer Correct ?    0 Yes 12 No

Post New Answer

More SQL PLSQL Interview Questions

What will you get by the cursor attribute sql%rowcount?

0 Answers  


Is sql sequential or random?

0 Answers  


Can we commit inside a trigger?

0 Answers  


what are aggregate and scalar functions? : Sql dba

0 Answers  


what is a cursor? : Sql dba

0 Answers  






How do you create a unique index?

0 Answers  


Is microsoft sql free?

0 Answers  


table name :Tab fields name 1.trx_no (pk) 2.trx_date 3.account code (7 char) 4.account type (1 char) 5.amt Tab contains account code day wise debit and credit transaction , account type fiels can have 2 value D for debit and c for Credit . write a query to display the account code wise total debit and credit bal for the month of april 2004. write a query to display account code wise new amt credit for the april 2004

2 Answers   Maruti Suzuki,


What is the difference between partitioning and sharding?

0 Answers  


What is the difference between in and between in sql?

0 Answers  


Does sql require a server?

0 Answers  


What plvcmt and plvrb does in pl/sql?

0 Answers  


Categories