Home » SQL & PL/SQL » SQL & PL/SQL » How to display employee table information based on salary in different ranges (Oracle 11g, windows)
How to display employee table information based on salary in different ranges [message #642375] Wed, 09 September 2015 03:16 Go to next message
nbarun07
Messages: 3
Registered: September 2015
Location: Bangalore
Junior Member
I have a table employees with employee details. I want list the employees based on the order of salary range. For eg., First list list of employees who are there i salary range 1000 - 3000, then 3000 - 5000, then 5000 - 10000. How to write sql query to solve this? your answers are appreciated.

[Updated on: Wed, 09 September 2015 03:18]

Report message to a moderator

Re: How to display employee table information based on salary in different ranges [message #642376 is a reply to message #642375] Wed, 09 September 2015 03:45 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

I assume that this is a college homework assignment? You need to provide the CREATE TABLE statement and a few INSERT statements (or if you are using oine of the standard demo schemas, say so), the SQL you have tried so far, and the result you want. No-one will give you the full answer (I hope) but they will help.

Going by the information so far, it looks to me as just a simple SELECT with an ORDER BY clause.
Re: How to display employee table information based on salary in different ranges [message #642377 is a reply to message #642375] Wed, 09 September 2015 03:54 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
SELECT * FROM emp WHERE sal BETWEEN <lower bound> AND <upper bound> ORDER BY sal;


The WHERE clause is to filter the rows, put required lower bound and upper bound to filter the rows based on salary. Order by is to sort the output, by default in ascending order.
Re: How to display employee table information based on salary in different ranges [message #642378 is a reply to message #642377] Wed, 09 September 2015 04:11 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Just in case, if you have started learning Oracle SQL, then spend good time reading the Database SQL Language Reference.
Re: How to display employee table information based on salary in different ranges [message #642381 is a reply to message #642377] Wed, 09 September 2015 04:27 Go to previous messageGo to next message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Quote:

No-one will give you the full answer (I hope) but they will help.

Wink
Re: How to display employee table information based on salary in different ranges [message #642382 is a reply to message #642381] Wed, 09 September 2015 04:31 Go to previous messageGo to next message
nbarun07
Messages: 3
Registered: September 2015
Location: Bangalore
Junior Member
Thank you all for your responses.
Here is my expected output. First salary range 3001 - 5000, then 1000 - 3000, then 5001 - 10000.

empid name salary
1 david 3500
2 donald 4500
3 den 2000
4 steven 2200
5 Alexander 9000

something like this,

select t.*,
case
when salary between 3000 and 5000 then 1
when salary between 1000 and 3000 then 2
when salary between 5000 and 10000 then 3
else 99
end range
from employees t
order by range, 1, 2;
Re: How to display employee table information based on salary in different ranges [message #642384 is a reply to message #642382] Wed, 09 September 2015 04:52 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Come on, man. You've ignored my reply completely, haven't you? If you want more help, please read it again.
Re: How to display employee table information based on salary in different ranges [message #642385 is a reply to message #642384] Wed, 09 September 2015 05:03 Go to previous messageGo to next message
nbarun07
Messages: 3
Registered: September 2015
Location: Bangalore
Junior Member
Sorry John. I didn't ignore your reply. I am beginner to this forum and posted my question what i expected. I will read OraforumGuide and understand it.
Re: How to display employee table information based on salary in different ranges [message #642387 is a reply to message #642385] Wed, 09 September 2015 05:05 Go to previous messageGo to next message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Quote:
You need to provide the CREATE TABLE statement and a few INSERT statements
Re: How to display employee table information based on salary in different ranges [message #642400 is a reply to message #642385] Wed, 09 September 2015 10:07 Go to previous message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
nbarun07 wrote on Wed, 09 September 2015 05:03
Sorry John. I didn't ignore your reply. I am beginner to this forum and posted my question what i expected. I will read OraforumGuide and understand it.

You are not beginner anymore after your first post and first feedback.
Previous Topic: Different way of writing OR condition
Next Topic: hierarchial query
Goto Forum:
  


Current Time: Thu Apr 25 05:34:03 CDT 2024