Difference between revisions of "Vnořené dotazy - možné řešení"

From Wikivyuka
Jump to: navigation, search
 
m
 
Line 6: Line 6:
 
                 WHERE last_name = 'Gates');
 
                 WHERE last_name = 'Gates');
  
  SELECT MAX(AVG(salary)) FROM employees GROUP BY job_id;
+
  SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id;
 
  .
 
  .
 
  SELECT e.job_id, j.job_title, AVG(salary)
 
  SELECT e.job_id, j.job_title, AVG(salary)

Latest revision as of 05:42, 18 March 2014

SELECT last_name, salary
FROM employees
WHERE salary >
              (SELECT salary
               FROM employees
               WHERE last_name = 'Gates');
SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id;
.
SELECT e.job_id, j.job_title, AVG(salary)
  FROM employees e, jobs j
  WHERE e.job_id = j.job_id
  GROUP BY e.job_id, j.job_title
  HAVING AVG(salary) = (SELECT MAX(AVG(salary))
                          FROM employees
                          GROUP BY job_id);
SELECT e.job_id, j.job_title, AVG(salary)
 FROM employees e, jobs j
 WHERE e.job_id = j.job_id
 GROUP BY e.job_id, j.job_title
 HAVING   AVG(salary) = (SELECT MIN(AVG(salary))
                         FROM employees
                         GROUP BY job_id);
SELECT e.employee_id, e.last_name, e.salary, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id 
AND e.salary in (SELECT MIN(salary)
                FROM  employees
                GROUP BY department_id);
SELECT employee_id, last_name, job_id, salary-(SELECT AVG(salary) FROM employees) viceNezPrumer
FROM employees
WHERE salary > 
              (SELECT AVG(salary) FROM employees);

Stránka Opakování SQL

Hlavní stránka předmětu