Solved

Oracle SQL - Case Expression

Posted on 2011-02-14
3
357 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 31

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
File generation using utl_file 4 30
dates - loop 12 41
sql query 9 21
How to simplify my SQL statement? 12 16
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

757 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

13 Experts available now in Live!

Get 1:1 Help Now