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
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 |
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 |
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 |
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 |
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 |
In a PL/SQL block,which loop type should be used in a performance point of view & Why (as both loops can do the same task) 1) open - Fetch loop 2) for loop
If a procedure within a package is invalidated whether the entire package will be invalid and has to be recompiled again?
I have done oracle 10g. I need a project knowledge. So if u please send a project how it should be done,Or you can send email link. I will be very grateful to u.
How can you maintain the integrity of your database on instances where deleting an element in a table result in the deletion of the element(s) within another table?
what is difference b/w pravite procedures and public procedures?
3 Answers Steria, Wipro, Zensar,
What is the difference between inner join and left join?
How to find string or key value using pl/sql code?
What is auto increment in sql?
What is the most common sql injection tool?
How do I count duplicates in sql?
how to retrieve only duplicate values in a table
What is trigger in flip flop?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)