Home » Education » 19 | GROUP BY Clause | Introduction to GROUP BY clause | How does it work | SQL | DBMS |In Nepali.

19 | GROUP BY Clause | Introduction to GROUP BY clause | How does it work | SQL | DBMS |In Nepali.

Written By Everything 360 on Tuesday, Apr 18, 2023 | 11:25 AM

 
The GROUP BY clause is a clause in SQL that is used to group together rows in a table based on a common column or columns, and perform aggregate functions on each group. The syntax for the GROUP BY clause is as follows: SELECT column1, column2, aggregate_function(column3) FROM table_name GROUP BY column1, column2; In this example, column1 and column2 are used to group the data and column3 is used to perform an aggregate function such as SUM, AVG, COUNT, MAX, or MIN on each group. When the GROUP BY clause is used in a SQL query, it creates subsets of data based on the values in the specified columns. The aggregate function is then performed on each subset, returning a single value for each group. It is important to note that any columns that are not included in the GROUP BY clause must be included in an aggregate function or in the SELECT statement. Otherwise, the SQL engine will return an error. The GROUP BY clause is a powerful tool for data analysis and reporting in SQL, allowing you to summarize large datasets and extract insights from them.