Dotazy - agregované funkce - možné řešení
From Wikivyuka
- SELECT COUNT(*) FROM employees;
- SELECT COUNT(*) FROM employees WHERE department_id=80;
- SELECT COUNT(*) FROM departments;
- SELECT COUNT(DISTINCT department_id) FROM employees;
- SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary) FROM EMPLOYEES e, DEPARTMENTS d WHERE e.department_id=d.department_id AND d.department_name = 'IT';
- SELECT AVG(salary), department_id FROM employees GROUP BY department_id;
- SELECT department_id, AVG(salary) FROM employees HAVING AVG(salary) > 7000 GROUP BY department_id;
- Pomocí vnořeného dotazu:
SELECT last_name, salary FROM employees WHERE salary = (SELECT max(salary) FROM employees);