PL/SQL Group By

The Group By clause is used when an aggregate function (count, max, min, sum, avg) exists in the pl/sql query.

SQL Query

SELECT c.course_id, c.name, c.description, o.order_id, c.price
FROM course c, orders o
WHERE o.course_id = c.course_id;

Output

COURSE_IDNAMEDESCRIPTIONORDER_IDPRICE
1SQL 1SQL course for beginners2210
1SQL 1SQL course for beginners110
4PHPPHP course375
5CSSLearn CSS2120
5CSSLearn CSS220

Group By 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;

Output

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