w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the full name, and salary, for all employees whose salary is out of the range 7000 and 15000 and arranged the full name in ascending order

SQL SORTING and FILTERING on HR Database: Exercise-11 with Solution

11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000 and make the result set in ascending order by the full name.

Sample table : employees


Sample Solution:

SELECT first_name || ' ' || last_name as Name, salary
 FROM  employees
   WHERE salary NOT BETWEEN 7000 AND 15000
     ORDER BY first_name || ' ' || last_name;

Sample Output:

       name        |  salary
-------------------+----------
 Alana Walsh       |  3100.00
 Alexander Khoo    |  3100.00
 Alexis Bull       |  4100.00
 Amit Banda        |  6200.00
 Anthony Cabrio    |  3000.00
 Britney Everett   |  3900.00
 Bruce Ernst       |  6000.00
 Charles Johnson   |  6200.00
 Curtis Davies     |  3100.00
 David Austin      |  4800.00
 David Lee         |  6800.00
 Diana Lorentz     |  4200.00
 Donald OConnell   |  2600.00
 Douglas Grant     |  2600.00
 Girard Geoni      |  2800.00
 Guy Himuro        |  2600.00
 Hazel Philtanker  |  2200.00
 Irene Mikkilineni |  2700.00
 James Landry      |  2400.00
 James Marlow      |  2500.00
 Jason Mallin      |  3300.00
 Jean Fleaur       |  3100.00
 Jennifer Dilly    |  3600.00
 Jennifer Whalen   |  4400.00
 John Seo          |  2700.00
 Joshua Patel      |  2500.00
 Julia Dellinger   |  3400.00
 Julia Nayer       |  3200.00
 Karen Colmenares  |  2500.00
 Kelly Chung       |  3800.00
 Kevin Feeney      |  3000.00
 Kevin Mourgos     |  5800.00
 Ki Gee            |  2400.00
 Laura Bissot      |  3300.00
 Lex De Haan       | 17000.00
 Luis Popp         |  6900.00
 Martha Sullivan   |  2500.00
 Michael Rogers    |  2900.00
 Mozhe Atkinson    |  2800.00
 Nandita Sarchand  |  4200.00
 Neena Kochhar     | 17000.00
 Pat Fay           |  6000.00
 Peter Vargas      |  2500.00
 Randall Matos     |  2600.00
 Randall Perkins   |  2500.00
 Renske Ladwig     |  3600.00
 Samuel McCain     |  3200.00
 Sarah Bell        |  4000.00
 Shanta Vollman    |  6500.00
 Shelli Baida      |  2900.00
 Sigal Tobias      |  2800.00
 Stephen Stiles    |  3200.00
 Steven King       | 24000.00
 Steven Markle     |  2200.00
 Sundar Ande       |  6400.00
 Sundita Kumar     |  6100.00
 Susan Mavris      |  6500.00
 Timothy Gates     |  2900.00
 TJ Olson          |  2100.00
 Trenna Rajs       |  3500.00
 Valli Pataballa   |  4800.00
 Vance Jones       |  2800.00
 Winston Taylor    |  3200.00
(63 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the full name, and salary, for all employees whose salary is out of the range 7000 and 15000 and arranged the full name in ascending order - Duration

Rows:

Query visualization of Display the full name, and salary, for all employees whose salary is out of the range 7000 and 15000 and arranged the full name in ascending order - Rows

Cost:

Query visualization of Display the full name, and salary, for all employees whose salary is out of the range 7000 and 15000 and arranged the full name in ascending order - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.
Next: Write a query in SQL to display the full name (first and last), job id and date of hire for those employees who was hired during November 5th, 2007 and July 5th, 2009.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming