(SQL Tutorial #13) HAVING clause with GROUP BY (HAVING clause VS. WHERE clause)
Автор: aPiece ofCode Labs
Загружено: 2020-05-05
Просмотров: 10
Описание:
Learn how to use HAVING clause with GROUP BY in SQL. Also, learn the difference between HAVING clause and WHERE clause.
► The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.
► Queries used in this video:
1. SELECT * FROM hr.employees;
2. Show number of employee_id, department_id for each department where number of employee_ids is more than 3. Sort in ascending order.
SELECT COUNT(employee_id), department_id
FROM hr.employees GROUP BY department_id
WHERE COUNT(employee_id) ▶️ 3 ORDER BY COUNT(employee_id) ASC;
VS.
SELECT COUNT(employee_id), department_id
FROM hr.employees GROUP BY department_id
HAVING COUNT(employee_id) ▶️ 3 ORDER BY COUNT(employee_id) ASC;
3. Show all job_id and average salary who work as any of these jobs IT_PROG, SA_REP, FI_ACCOUNT, AD_VP
select job_id, avg(salary) as "average salary" from hr.employees group by job_id
having job_id IN ('IT_PROG', 'SA_REP', 'FI_ACCOUNT', 'AD_VP');
**▶️ means greater than & ◀️ means less than**
► This video is a part of SQL for Beginners Tutorial series.
► See the PLAYLIST to learn more about SQL commands: • SQL Quick Tutorials for Beginners [Best St...
👍👍 👍PLEASE LIKE & SHARE THIS VIDEO with your friends to support us grow!
🔔🔔 🔔DON'T FORGET TO SUBSCRIBE to watch future tutorials / @apieceofcodelabs
TURN ON THE 🔔 BELL ICON TO GET UPDATES FIRST!📩📩📩
HAVING clause with GROUP BY | Difference between HAVING clause and WHERE clause |
#havingClauseWithGroupBy #DifferenceBetweenHavingClauseAndWhereclause
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: