This video covers advanced SQL Aggregate Functions with GROUP BY and HAVING.
Queries:
-- all examples are based on northwind database
USE northwind;
-- How many customers are from the USA?
SELECT COUNT(*)
FROM Customers
WHERE Country='USA';
-- How many customers are from Germany?
SELECT COUNT(*)
FROM Customers
WHERE Country='Germany';
-- How many customers are from the UK?
SELECT COUNT(*)
FROM Customers
WHERE Country='UK';
-- How many customers are there in each country?
SELECT Country, COUNT(*) AS TotalNoOfCustomers
FROM Customers
GROUP BY Country;
-- Which countries have at least 5 customers?
SELECT Country, COUNT(*) AS TotalNoOfCustomers
FROM Customers
GROUP BY Country
HAVING COUNT(*) =5; (use greater or equals, check the video for the syntax, YouTube doesn't allow angle brackets)
-- How many products are there in each category?
SELECT CategoryID, COUNT(*) AS TotalNoOfProducts
FROM Products
GROUP BY CategoryID;