w3resource

SQL SORTING and FILTERING on HR Database: Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50

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

33. From the following table, write a SQL query to find those employees who have no commission percentage and salary within the range 7000, 12000 (Begin and end values are included.) and works in the department number 50. Return all the fields of employees.

Sample table : employees


Sample Solution:

SELECT * 
	FROM employees 
		WHERE commission_pct IS NULL 
			AND salary BETWEEN 7000 AND 12000 
				AND department_id=50;

Sample Output:

employee_id | first_name | last_name | email | phone_number | hire_date | job_id | salary | commission_pct | manager_id | department_id
-------------+------------+-----------+-------+--------------+-----------+--------+--------+----------------+------------+-------------
(0 rows)

Relational Algebra Expression:

Relational Algebra Expression: Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50.

Relational Algebra Tree:

Relational Algebra Tree: Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50.

Practice Online


N.B.: In certain instances not null is removed in table structure, so results may vary.

HR database model

Query Visualization:

Duration:

Query visualization of Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50 - Duration

Rows:

Query visualization of Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50 - Rows

Cost:

Query visualization of Display the details of the employees who have no commission percentage and salary between 7000 to 12000 and works in department 50 - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to find those employees who have completed their previous jobs. Return employee ID, end_date.
Next: From the following table, write a SQL query to compute the average salary of each job ID. Exclude those records where average salary is higher than 8000. Return job ID, average salary.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



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