What are difference between Group by and Having clause in SQL Server?

Group by Clause:

The GROUP BY clause is used in SQL for SELECT statement to collecting the data across multiple records and making the group of one or more columns.

SELECT Department1, SUM(ProductSales) AS “Total ProductSales”

FROM Product_order_details

GROUP BY Department1;

 

Having Clause:

The having clause is used for only on group rows of tables and act as a filter like as where clause. You can use having clause to filter data that that you get from group by clause in tables. For using the having clause in SQL Query first you need to use group by clause.

SELECT Department1, SUM(ProductSales) AS “Total ProductSales”

FROM Product_order_details

GROUP BY Department1

Having SUM(Total ProductSales) >50000

Leave a Reply

Your email address will not be published. Required fields are marked *

6 + 8 =


All Rights Reserved 2019 | DesignzRush (OPC) Pvt. Ltd.
Inline
Inline