To create a SQL query that satisfies your requirements, you would need to select the relevant fields from the employee table, apply the conditions for department and salary, and then sort the results accordingly. Assuming your table is named employees
and the relevant fields are employee_number
, name
, salary
, and department_id
, the query would look something like this:
SELECT employee_number, name, salary
FROM employees
WHERE department_id IN (10, 20)
AND salary > 10000
ORDER BY name ASC, salary DESC;
Explanation:
- SELECT: This part defines which columns you want to retrieve — employee number, name, and salary.
- FROM: Specifies the table to query data from (
employees
). - WHERE: This clause is used to filter the results. It checks that the
department_id
is either 10 or 20 and that thesalary
is greater than R10000. - ORDER BY: This clause sorts the results first by
name
in ascending order (ASC
). If there are employees with the same name, it then sorts bysalary
in descending order (DESC
).
Make sure to adjust the table and column names as per your actual database schema if they differ.