Docsity

SQL HAVING Clause SQL HAVING Clause, Assignments of Computer Science

Toggle sidebar
bg1
SQLHAVINGClause
Havingclause is used with SQL Queries to give more precise
condition for a statement. It is used to mention condition
inGroup bybased SQL queries, just likeWHEREclause is used
withSELECTquery.
SyntaxforHAVINGclause is,
SELECT column_name, function(column_name)
FROM table_name
WHERE column_name condition
GROUP BY column_name
HAVING function(column_name) condition
Example of SQL Statement usingHAVING
Consider the followingSaletable.
oid order_name previous_balance customer
pf3

Partial preview of the text

Download SQL HAVING Clause SQL HAVING Clause and more Assignments Computer Science in PDF only on Docsity!

SQL HAVING Clause

Having clause is used with SQL Queries to give more precise condition for a statement. It is used to mention condition in Group by based SQL queries, just like WHERE clause is used with SELECT query. Syntax for HAVING clause is, SELECT column_name, function(column_name) FROM table_name WHERE column_name condition GROUP BY column_name HAVING function(column_name) condition Example of SQL Statement using HAVING Consider the following Sale table. oid order_name previous_balance customer

11 ord1 2000 Alex 12 ord2 1000 Adam 13 ord3 2000 Abhi 14 ord4 1000 Adam 15 ord5 2000 Alex Suppose we want to find the customer whose previous_balance sum is more than 3000. We will use the below SQL query, SELECT * FROM sale GROUP BY customer HAVING sum(previous_balance) > 3000 Result will be, oid order_name previous_balance customer 11 ord1 2000 Alex