Tema Nr. 8: Observaţie!
Tema Nr. 8: Observaţie!
8
Observaţie!
Scrieţi rezolvarea direct în acest document!
1. Each of the following SQL queries has an error. Find the error and correct it. Use Oracle
Application Express to verify that your corrections produce the desired results.
2. Write a query that will return both the maximum and minimum average salary grouped by
department from the employees table.
SELECT MAX(AVG(e.salary)),MIN(AVG(e.salary))
FROM employees e , departments d
WHERE e.department_id = d.department_id
Group BY e.department_id ;
3. Write a query that will return the average of the maximum salaries in each department for the
employees table.
SELECT FLOOR(AVG(MAX(e.salary)))
FROM employees e , departments d
WHERE e.department_id=d.department_id
Group BY d.department_name
5. What are the department names of the Oracle departments that have the same location ID as
Seattle?
SELECT department_name
FROM departments
WHERE location_id=(SELECT location_id from locations WHERE city='Seattle');
6. Write a query to return all those employees who have a salary greater than that of Lorentz and are
in the same department as Abel.
7. Write a query to return all those employees who have the same job id as Rajs and were hired
after Davies.
8. Write a query to return a list of department id’s and average salaries where the average salary is
greater than Ernst’s salary.
9. Return the department ID and minimum salary of all employees, grouped by department ID,
having a minimum salary greater than the minimum salary of those employees whose department
ID is not equal to 50.
select last_name
from employees
where salary=any(select min(salary) from employees group by department_id);
11. The goal of the following query is to display the minimum salary for each department whose
minimum salary is less than the lowest salary of the employees in department 50. However, the
subquery does not execute because it has five errors. Find them, correct them, and run the query.
SELECT department_id
FROM employees
WHERE MIN(salary)
HAVING MIN(salary) >
GROUP BY department_id
SELECT MIN(salary)
WHERE department_id < 50;
select min(salary)
from employees
where min(salary)<(select min(salary) from employees where department_id=50);
12. Write a query that lists the highest earners for each department. Include the last_name,
department_id and the salary for each employee.
SELEct last_name,salary,department_id
FROM employees
WHERE salary=any(SELECT max(salary) FROM employees GROUP by department_id);