Concept explainers
Aggregate Functions:
SQL has some built-in functions and they are called as aggregate functions. SQL contains five built-in functions. They are:
- SUM – This function is used to add values from the particular column.
- Syntax: SELECT SUM(column_Name) FROM table_Name;
- COUNT – This is used to count the number of rows for the particular column.
- Syntax: SELECT COUNT(column_Name) FROM table_Name;
- MAX – This function is used to get the maximum value from the column.
- Syntax: SELECT MAX(column_Name) FROM table_Name;
- MIN – This function is used to get the minimum value from the column.
- Syntax: SELECT MIN(column_Name) FROM table_Name;
- AVG – This function is used to get the average of all the values from the column.
- Syntax: SELECT AVG(column_Name) FROM table_Name;
Grouping Rows:
SQL contains “GROUP BY” clause in order to group rows by common data. Though it is very powerful feature, it is hard to understand.
Syntax:
SELECT column_Name1 FROM table_Name GROUP BY column_Name2;
Example: Consider a table “student” contains two columns “student_Name” and “Department”. “GROUP BY” clause is used when there is a need to get the number of students from each department. The query for this scenario is given as follows.
SELECT department, COUNT (department) FROM student GROUP BY department;
When the above query is executed, number of students from each department will be displayed.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Database Systems: Design, Implementation, & Management
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningA Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr