ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

SQL Having Clause

sqltuts

Having clause is used to mention condition in Group based SQL functions, just like WHERE clause .It acts as the same way as does where clause is used:

Syntax for having will be,

  1. select column_name, function(column_name)
  2. FROM table_name
  3. WHERE column_name condition
  4. GROUP BY column_name
  5. HAVING function(column_name) condition

 

Example of HAVING Statement

Consider the following shopping list table.

Sid order_name previous_balance customer
1 ord1 2850 ram
35 ord2 1520 sham
36 ord3 2890 ghanshyam
42 ord4 1780 tom
31 ord5 2220 ram

Suppose we want to find the customer whose previous_balance sum is more than 3000.

We will use the below SQL query for  a given database,

  1. SELECT *
  2. from shopping list customer
  3. having sum(previous_balance) > 3000

Result will be,

oid order_name previous_balance customer
11 ord1 2850 ram

 

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

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

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!