Computer Science‎ > ‎

Databases and SQL: Aggregate Functions in SQL - Sum, Max, Min, Avg (Average)


Aggregate functions like SUM, MAX, MIN, AVG are useful for obtaining these values for numeric fields at times.

AGGREGATE FUNCTIONS


15. Find the sum of resources required for all students in the course ‘Automobile Engg’ . Also find, the maximum resource , the minimum resource and the average resource  in this course.

-> SELECT SUM(No_of_Resources), MAX(No_of_Resources),

       MIN(No_of_Resources), AVG(No_of_Resources)

   FROM (Course AS C JOIN Resource AS R ON C.CId = R.CId)
   WHERE CName= ‘Automobile Engg’;

SUM

MAX

MIN

AVG

20

6

4

5

Comments