Multiple-Row Function and Group by Clause
Multiple-Row Function and Group by Clause
Objectives
At the end of this lesson, you should be
able to:
Identify
Maximum GPA in
the STUDENT table
3.05
1.89
3.89
2.22
3.11
3.34
1.88
3
1.88
2.74
3.12
Highest GPA
3.89
Description
Max (expr)
Min (expr)
Avg (expr)
Sum (expr)
Count (expr)
Count (*)
---------------3.89 Williams
1400
5600
Average
2.84714285714286
Total GPA
39.86
query.
SELECT Count(*) AS [No of Students]
FROM Student;
Output:
No of Students
16
The example above will calculate the number of rows from the STUDENT table.
nonnull rows.
SELECT Count(GPA) As [Earn GPA]
FROM Student;
Output:
Earn GPA
14
The example above calculate the number of rows from the GPA columns
that are not null.
Group
column.
SELECT AVG(GPA) AS [Average GPA]
FROM Student;
Output:
Average GPA
2.84714285714286
The
GPA
DCS
3.21
DCS
1.89
DCS
3.89
DCS
2.74
DIC
3.34
DIC
2.22
DCS
3.89
DIC
3.34
DIC
3.34
DIC
3.12
DICT
3.11
DIT
3.82
DICT
DICT
3.11
DICT
DIT
3.82
DIT
3.05
DIT
1.88
DIT
1.88
DNC
DNC
Highest GPA
Use
column, group_function
table
condition]
group_by_expression]
column];
CourseID
Highest GPA
DCS
3.89
DIC
3.34
DICT
3.11
DIT
3.82
DNC
Highest GPA
3.89
3.34
3.11
3.82
course.
SELECT CourseID, Count(*) As [Course Students]
FROM Student
Group By CourseID;
Output:
CourseID
Course Students
DCS
DIC
DICT
DIT
DNC
Course Students
DNC
DICT
DIT
DIC
DCS
Summary
Showing
functions
Grouping by rows to achieve more than
one result