Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle Query

Posted on 2014-04-03
2
Medium Priority
?
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

718 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