SQL Queries for Employee Data Analysis
SQL Queries for Employee Data Analysis
The query must filter based on the given department ids using the IN keyword, and then sort the results by "department_id" alphabetically. The SQL query is: SELECT first_name, salary, department_id FROM employees WHERE department_id IN (50, 90, 200) ORDER BY department_id ASC .
To retrieve the desired information, the query would specify conditions to filter employees with a salary greater than 3000 and who belong to department 90. The results will then be sorted by "employee_id" and "salary" using an ORDER BY clause, ensuring the ASC keyword for ascending order. The SQL query would be: SELECT department_id, last_name, salary FROM employees WHERE salary > 3000 AND department_id = 90 ORDER BY employee_id ASC, salary ASC .
To achieve this, the query would filter records having a null value in "COMMISSION_PCT" and then sort them in descending order by "job_id". The SQL query would be: SELECT job_id, last_name, COMMISSION_PCT FROM employees WHERE COMMISSION_PCT IS NULL ORDER BY job_id DESC .
To select employees with salaries within the specified range, a WHERE clause with the BETWEEN operator would be used. The SQL query for this task is: SELECT last_name, first_name, salary FROM employees WHERE salary BETWEEN 5000 AND 120000 .
To display last names where the second letter is 'e', the SQL query should use pattern matching with the LIKE operator. The appropriate condition would specify an underscore for the first character, 'e' for the second, and a percent sign for the remaining characters: SELECT last_name FROM employees WHERE last_name LIKE '_e%' .
To retrieve names starting with 'B', the SQL query would utilize the LIKE operator with 'B%' as the pattern. The SQL query is: SELECT first_name FROM employees WHERE first_name LIKE 'B%' .