SQL tutorial for using Having with Examples
The HAVING statment is added to SQL because the WHERE keyword could not be used with aggregate functions ( such as count, max …)
[info] Advanced SQL SELECT Tutorial using Aggegrate Functions by Examples [/info]
The syntax for using HAVING is as below:
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value;
Example for Database Structure
In order to demonstrate the usage of HAVING within SELECT statement, we will be using the following database during the course of this tutorial . The database is for an ecommerce store with 5 tables as :
Countries, Orders, Clients, Products, Prodcat
Questions
1 Find the customers who have over 16 orders ?
2 Find the first five countries with the largest number of orders WITH a total revenue over 11200?
No Responses