|
- SELECT last_name, salary, department_id
- FROM employees outer
- WHERE salary >
- (SELECT AVG(salary)
- FROM employees
- WHERE department_id =
- outer.department_id) ;
-
- select e.employee_id, e.last_name , a.avg_sal ,e.salary
- from
- (SELECT department_id , AVG(salary) avg_sal
- FROM employees group by department_id) a , employees e
- where e.department_id=a.department_id and e.salary > a.avg_sal;
-
- select e.employee_id, e.last_name , a.avg_sal ,e.salary
- from
- (SELECT department_id , AVG(salary) avg_sal
- FROM employees group by department_id) a join employees e
- using (department_id ) where e.salary > a.avg_sal;
-
复制代码- SELECT employee_id, last_name
- FROM employees e
- ORDER BY
- (SELECT department_name
- FROM departments d
- WHERE e.department_id = d.department_id);
复制代码
- select department_id, department_name,
- (select count(*)
- from
- employees e
- where e.department_id = d.department_id) as emp_count
- from
- departments d;
- select d.department_id, d.department_name , count(*)
- from employees e , departments d
- where e.department_id (+) =d.department_id
- group by d.department_id, d.department_name;
复制代码
|
|