Solved

Oracle Query

Posted on 2014-04-03
2
369 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 31

Accepted Solution

by:
awking00 earned 300 total points
Comment Utility
select id, type, decode(Type,'D',Amount,'C',-1 * Amount) Amount
0
 
LVL 73

Assisted Solution

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now