SQL Group By

The GROUP BY is used in conjunction with the aggregate functions to group the result-set by columns.
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name;
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;

Leave a Reply