You need to know about the
CASE
statement in SQL - here is an article on that subject
A Simple Use of SQL CASE Expression[
^]
You also need to know about the
BETWEEN
clause - here is the
reference[
^]
Based on your expected results you will end up with something like
Select emp_id, emp_name,
CASE when salary BETWEEN 1000 AND 2000 THEN 1
WHEN salary BETWEEN 2100 AND 3000 THEN 2
WHEN salary BETWEEN 3100 AND 4000 THEN 3
ELSE 0 END AS level
Note that I've introduced a default situation of level=0
Personally I think you might have meant your ranges to have been 1000-2000,
2001-3000 and
3001-4000 - unless you deliberately meant to leave a 100 unit gap between them