Tuesday, October 3, 2023

GROUP BY statement in SQL

 

Cú pháp câu lệnh: 
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

Ví dụ: 
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;