Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle Query

Posted on 2014-04-03
2
Medium Priority
?
390 Views
Last Modified: 2014-04-03
Greetings,

I have 3 fields with sampel data in oracle below.
I need to a query to get the total amount(group by ID). If type='D' the positive number, If Type='C' then it should be a negative number.



ID Type   Amount
1     D       200
2     C       100

Thanks in advance.
0
Comment
Question by:mrong
2 Comments
 
LVL 32

Accepted Solution

by:
awking00 earned 1200 total points
ID: 39976089
select id, type, decode(Type,'D',Amount,'C',-1 * Amount) Amount
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 800 total points
ID: 39976098
select id, sum(case when type  ='D' then amount else  -amount end) from yourtable
group by id
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question