Group By in SQL
Group By statement is SQL is used to group rows that have same values into summary rows like "Find the number of Customers in each country"
Group by is used by aggregate functions like MIN(), MAX(),SUM(),AVG(),COUNT() to group the result set by one or more columns
Eg., SELECT Country, COUNT(CustomerID) FROM Customers
GROUP BY COUNTRY;
Result:
India 10,000
US 5000
China 2000
GROUP BY Example with JOIN:
SELECT S.ShipperName, COUNT(O.OrderID) FROM
ShipperTable S LEFT JOIN Orders O on S.ShipperId=O.ShipperId
GROUP BY S.ShipperName;
Comments
Post a Comment