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

Popular posts from this blog

Jenkins CICD in One Page

Why do we need a build tool?

Deutsche Bank Interview Questions - 2024