w3resource

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. From the following table, write a SQL query to find those employees whose salary is not in the range 7000 and 15000 (Begin and end values are included). Sort the result-set in ascending order by the full name (first and last). Return full name and salary.

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: From the following table, write a SQL query to find those employees whose first name ends with the letter ‘m’. Return the first and last name, and salary.
Next: From the following table, write a SQL query to find those employees who were hired during November 5th, 2007 and July 5th, 2009. Return full name (first and last), job id and hire date.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS