SQL Bootcamp: Session 6 (Group by in SQL) | Where vs Having in SQL | SQL for Data Analytics

Published: 01 January 1970
on channel: TechiesAdda
53
1

Complete Theory and Video Script:

In SQL, the GROUP BY clause is used to group rows that have the same values in one or more columns.
It is often used in conjunction with aggregate functions such as COUNT, SUM, AVG, MAX, and MIN to
summarize or perform calculations on the grouped data.


------Create Table-----------
create table orders
(
Order_id int primary key not null,
customer_id int,
product_name varchar(20),
order_date date
);
go
---------Insert Data-------
insert into orders
values
(1,101,'A','2023-05-01')
,(2,102,'B','2023-05-01')
,(3,102,'A','2023-05-02')
,(4,103,'C','2023-05-03')
,(5,103,'D','2023-05-04')
,(6,104,'E','2023-05-05')
----------Check Data (Select)
Select * from Orders
-----------------------------
Select
count(order_id) as Order_Count
,customer_id
from orders
Group by customer_id
-------------------Where vs Having-----------
Select * from Orders
where order_date (Greater than sign here) '2023-05-01'
-----------------------
Select
count(order_id) as Order_Count
,customer_id
from orders
Group by customer_id
having count(order_id) (Greater than sign here) 1

--------------------NOTE------------------
Replace (Greater than sign here) by the sign, i have limitatio.
Because Youtube doesn't allow that sign in description.


On this page of the site you can watch the video online SQL Bootcamp: Session 6 (Group by in SQL) | Where vs Having in SQL | SQL for Data Analytics with a duration of hours minute second in good quality, which was uploaded by the user TechiesAdda 01 January 1970, share the link with friends and acquaintances, this video has already been watched 53 times on youtube and it was liked by 1 viewers. Enjoy your viewing!