PL/SQL Having

The HAVING clause is used like search condition for a group or an aggregate function used in an select statement.

SQL Query

 
SELECT c.course_id, c.name, c.description, c.price, 
		SUM(c.price) AS amount, COUNT(c.course_id) AS quantity
FROM course c, orders o
WHERE o.course_id = c.course_id
GROUP BY c.course_id, c.name, c.description, c.price;

Output

COURSE_IDNAMEDESCRIPTIONPRICEAMOUNTQUANTITY
1SQL 1SQL course for beginners10202
4PHPPHP course75751
5CSSLearn CSS20402

Having example

 
SELECT c.course_id, c.name, c.description, c.price, 
		SUM(c.price) AS amount, COUNT(c.course_id) AS quantity
FROM course c, orders o
WHERE o.course_id = c.course_id
GROUP BY c.course_id, c.name, c.description, c.price
HAVING COUNT(c.course_id) > 1
AND SUM(c.price) > 20;

Output

COURSE_IDNAMEDESCRIPTIONPRICEAMOUNTQUANTITY
5CSSLearn CSS20402