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_ID NAME DESCRIPTION ORDER_ID PRICE
1 SQL 1 SQL course for beginners 22 10
1 SQL 1 SQL course for beginners 1 10
4 PHP PHP course 3 75
5 CSS Learn CSS 21 20
5 CSS Learn CSS 2 20

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_ID NAME DESCRIPTION PRICE AMOUNT QUANTITY
1 SQL 1 SQL course for beginners 10 20 2
4 PHP PHP course 75 75 1
5 CSS Learn CSS 20 40 2