Use of GROUP BY Statement in SQL

Use of GROUP BY Statement in SQL:

(1) “GROUP BY” is used to group rows having the same value in a column (grouping of records on the basis of column).

(2) “GROUP BY” is mainly used with the combination of COUNT(), MAX(), MIN().

(3) Syntax of “GROUP BY” statement is:

SELECT Col1, Col2, …ColN
FROM table_name1

(4) Let’s take an example, Grouping on the “City” column in Vendor Table.

(5) Select the database in the SQL server and click on the “New Query” button as shown.

Select the database in SQL server and click on the New Query

(6) After that new query editor open as shown.

SQL new query editor open

(7) After doing the above steps, write a query in the editor, as shown.

GROUP BY Statement Query in SQL

Source Code:

–// With “GROUP BY”
Select Count(No_) AS [Customer Count],City
from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
Group BY City
Order By Count(No_) Desc
–// With “GROUP BY

(8) After writing the query, then execute the query (Shortcut keys is F5) as shown.

execute group by statement in sql

(9) After executing the two queries in the same editor, SQL gives two results.

How to Fix WORK DATE issue in D365 BC
Microsoft D365 Business Central Process Flow
AL Control Statements in Business Central
How to Create Sales and Receivables Setup in D365 BC
Understanding the General Ledger and the COA– Microsoft

Leave a Reply