Group By the function in SQL
The problem of Group By the function in SQL
In this blog, we will understand the group by the function of SQL. It is one of the most common functions in SQL. This clause is mainly helpful in grouping the column data of any table. The best benefit of using this function is that the comparison operators work among the groups instead of individual columns.
Now let’s understand the working of the group by clause of SQL.
Solution
Group By X Put everyone in one category who has the same value for X as you do.
Group By X, Y is meant to group all individuals with the same values for both X and Y.
An example of the above concept is shown below with the help of a table.
By executing the following query the result we get will be as follows:
select Subject, Count(*) from Subject_Selection group by Subject;
Output
If we group two columns the output changes. This is so that we can calculate all the aggregate functions (Count, Sum, Average, etc.) for each group. This is because when we group by two columns, it is telling us to “group them so that all of those with the same Subject and Semester are in the same group”.
Also Read: What is Prompt and how to use it?