Solved

Oracle SQL - Case Expression

Posted on 2011-02-14
3
359 Views
Last Modified: 2012-05-11
I need assistance in processing a table with the columns of departmetn_id, last_name, salary where the following condiions apply: - New column called "New Salary"

Must use Case expression

When department_id is 10 then 1.25 *salary
When department_id is 90 then 1.50*salary
When department_id is 130 then 1.75* salary
Otherwise display the old salary

0
Comment
Question by:dc0819
3 Comments
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 250 total points
ID: 34893965
try this :

select department_id, last_name, salary,
case
when department_id = 10 then 1.25 * salary
when department_id = 90 then 1.50 * salary
when department_id = 130 then 1.75 * salary
else salary end "New Salary"
from your_table;

0
 
LVL 13

Accepted Solution

by:
riazpk earned 250 total points
ID: 34893991
Alternatively, you can also use:
SELECT department_id, last_name, salary,
 CASE department_id
   WHEN 10 THEN salary*1.25
   WHEN 90 THEN salary*1.50
   WHEN 130 THEN salary*1.75
   ELSE salary
 END "NEw Salary"
FROM <Table Name>

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 34896958
You might consider using decode instead of case. See attached.
query.txt
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

785 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