How to Work with HAVING Clause in SQL

In this article I am going to explain how to work with HAVING Clause in SQL.
  • 1659

Introduction

In this article I am going to explain how to work with  HAVING Clause in SQL. GROUP BY clause is used to groups the rows of result set based on one or more columns or expression. GROUP BY clause is used in SELECT statements that include aggregate functions.

To put any condition with group by clause  we use HAVING clause. HAVING clause is used to specify a search condition for a group or an aggregate.

Example

SELECT vendorid, sum(invoicetotal)
as sum_invoicetotal
from mcninvoices
group by vendorid
having sum(invoicetotal) > 1200
order by sum_invoicetotal desc

Output

Clipboard14.jpg


© 2018 DotNetHeaven. All rights reserved.