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
Answer Posted / 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 |
Post New Answer View All Answers
Mention what does plvtab enables you to do when you showthe contents of pl/sql tables?
How do you identify a primary key?
hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews
How to assign sql query results to pl sql variables?
how to dump a table to a file with 'mysqldump'? : Sql dba
What is sql partition?
what is an execution plan? When would you use it? How would you view the execution plan? : Sql dba
Why partition by is used in sql?
what is the difference between char_length and length? : Sql dba
What is online transaction processing (oltp)?
What is the difference between an inner and outer join?
What does pl sql stand for?
How many types of relationship are there?
How can you view the errors encountered in a trigger?
What is substitution variable?