The GROUP BY is used in conjunction with the aggregate functions to group the result-set by columns.
Syntax:-
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name;
Example:-
If, we want to locate the number of visit. The subsequent SQL counts as Visit grouped by Visitors:-

SELECT Visitors.VisitorName, COUNT(visits.visitID) AS NumberOfvisits FROM visits LEFT JOIN Visitors ON visits.visitorID=Visitors.visitorID GROUP BY VisitorName;

Categories: SQL Function

0 thoughts on “SQL Group By”

Leave a Reply