The GROUP by statement is used with the aggregate functions to group the result by one or more columns.
GROUP by Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP by column_name;
We have a table "employee" as below:
employee
id first_name last_name salary
.......................................................
1 John Simp 10000
2 Chris Hely 25000
3 John Roy 20000
4 Jenny Mill 35000
5 Jenny Simpson 35000
GROUP by Example
Now we want to find occurrence of first name value in column "first_name" then you just need to write the below command:
SELECT first_name, COUNT(fistr_name) as count
FROM employee
GROUP by first_name;
Result:
first_name count
.............................
John 2
Chris 1
Jenny 2
Hope this will help you :)
0 Comment(s)