To create a SQL query that meets the specified requirements, you can use the following SQL statement. I'll assume that the relevant columns in your employees
table are employee_number
, name
, salary
, and department_id
. Here’s how the query would look:
SELECT employee_number, name, salary AS annual_salary
FROM employees
WHERE (department_id IN (10, 20))
AND salary > 10000
ORDER BY name ASC, salary DESC;
Explanation:
- SELECT statement: This selects the
employee_number
,name
, andsalary
(renamed toannual_salary
). - FROM clause: This specifies that the data comes from the
employees
table. - WHERE clause:
department_id IN (10, 20)
: Filters employees to those in departments 10 or 20.salary > 10000
: Ensures the salary is over R10000 per annum.
- ORDER BY clause:
- First sorts the results by
name
in ascending order. - If there are employees with the same name, it sorts them by
salary
in descending order.
- First sorts the results by
Make sure to adjust the column and table names if they differ in your database schema.