SQL Exercise: Employees whose commission is more than their salary
SQL employee Database: Exercise-15 with Solution
[An editor is available at the bottom of the page to write and execute the scripts.]
15. From the following table, write a SQL query to identify employees whose commissions exceed their salaries. Return complete information about the employees.
Sample table: employees
Pictorial Presentation:
Sample Solution:
SELECT *
FROM employees
WHERE commission>salary;
Sample Output:
emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id --------+----------+----------+------------+------------+---------+------------+-------- 66564 | MADDEN | SALESMAN | 66928 | 1991-09-28 | 1350.00 | 1500.00 | 3001 (1 row)
Explanation:
The provided query in SQL that selects all columns from the "employees" table where the commission is greater than the salary.
The "WHERE" clause filters the results for all employees whose commission is greater than their salary.
The query uses the greater than operator ">" to compare that the result set will only include employees where the commission is strictly greater than their salary.
Relational Algebra Expression:
Relational Algebra Tree:
Practice Online
Sample Database: employee
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Display the details of the employee BLAZE.
Next SQL Exercise: Employees whose salary is over 3000 after a 25% raise.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/sql-exercises/employee-database-exercise/sql-employee-database-exercise-15.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics