How to Create Compound Condition in HAVING Clause in SQL

In this article I am going to explain how to create compound condition in HAVING clause SQL.
  • 1977

Introduction

In this article I am going to explain how to create compound condition in HAVING clause 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.

WHERE clause is used before the rows are groped in SELECT statement that uses grouping and aggregate.

Having clause is used after the rows are groped in SELECT statement that uses grouping and aggregate.

We can put BETWEEN operator or logical operator like AND and OR operator in HAVING clause.

Example

select vendorname,sum(invoicetotal) as invo_total

from mcninvoices join mcnvendors

on mcninvoices.vendorid = mcnvendors.vendorid

group by vendorname

having sum(invoicetotal) between 1000 AND 5000

order by vendorname

Output

Clipboard06.jpg


© 2018 DotNetHeaven. All rights reserved.