GROUP FUNCTION
OR
AGGREGATE FUNCTION
BY
RAJESH RAO K
TYPES OF GROUP FUNCTION
 There are different types of Group
functions and each of the functions accepts
an argument.
 The following table identifies the options
that can use in the syntax
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to
something other than null (count all selected
rows using * including duplicate and rows with
nulls
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to
something other than null (count all selected
rows using * including duplicate and rows with
nulls
MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values
MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to
something other than null (count all selected
rows using * including duplicate and rows with
nulls
MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values
MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values
STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to
something other than null (count all selected
rows using * including duplicate and rows with
nulls
MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values
MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values
STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values
SUM ( [DISTINCT | ALL ] n) Sum values of n, ignoring null values
TYPES OF GROUP FUNCTION
GROUP FUNCTION DESCRIPTION
AVG (DISTINCT | ALL n) Average value of n, ignoring null values
COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to
something other than null (count all selected
rows using * including duplicate and rows with
nulls
MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values
MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values
STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values
SUM ( [DISTINCT | ALL ] n) Sum values of n, ignoring null values
VARIANCE ( [DISTINCT | ALL ] x) Variance of n, ignoring null values
Find the Maximum, Minimum, Sum and
Average of price in Book Table
 SELECT MAX(PRICE), MIN(PRINCE), SUM(PRICE),
AVG(PRICE) FROM BOOK;
 +---------------+---------------+----------------+---------------+
 | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) | AVG(PRICE) |
 +---------------+---------------+----------------+---------------+
 | 700 | 200 | 3575 | 357.5000 |
 +---------------+---------------+----------------+--------------+
 1 row in set (0.00 sec)
Find the Maximum, Minimum, Sum and
Average of price in SKYWARD Book
 SELECT MAX(PRICE), MIN(PRINCE), SUM(PRICE),
AVG(PRICE) FROM BOOK WHERE
PUBLISHER=‘SKYWARD’;
 +---------------+---------------+----------------+---------------+
 | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) | AVG(PRICE) |
 +---------------+---------------+----------------+---------------+
 | 300 | 200 | 1175 | 235 |
 +---------------+---------------+----------------+--------------+
 1 row in set (0.00 sec)
Find out the number of SKYWARD Books
present in the book table
 SELECT COUNT(*) FROM BOOK WHERE
PUBLISHER=‘SKYWARD’;
 +-------------+
 | COUNT(*) |
 +-------------+
 | 5 |
 +-------------+
 1 row in set (0.00 sec)
Find out Standard Deviation and
Variance of price in book table
 SELECT STDDEV(PRICE), VARIANCE(PRICE)
FROM BOOK WHERE PUBLISHER=‘SKYWARD’;
 +-------------------+----------------------+
 | STDDEV(PRICE) | VARIANCE(PRICE) |
 +--------------------+----------------------+
 | 37.4166 | 1400.0000 |
 +--------------------+----------------------+
 1 row in set (0.11 sec)
ORDER BY Clause
 To order of rows that are returned in a
query result is undefined.
 The ORDER BY Clause can be used to sort
the rows.
 If we use the ORDER BY clause, it must be
the last clause of the SQL statement.
 We can specify an expression, an alias or
a column position as the sort condition.
ORDER BY Clause - Syntax
 SELECT <COLUMS> FROM TABLENAME
 [ WHERE CONDITION(S) ]
 [ ORDER BY { COLUMN, EXPR, NUMERIC
POSITION} [ASC | DESC ] ];
 ORDER BY: Specifies the order in which
the retrieved rows are displayed.
 ASC orders the rows in ascending order
 DESC orders the rows in descending order
ORDER BY
Display book details in ascending order of
PUBISHER
 SELECT * FROM BOOK
 ORDER BY PUBLISHER ASC;
 +----------+--------------------------------------+----------+---------------+-------+
 | book id | title | author | publisher | price |
 +-----------+---------------------------------------+----------+--------------+-------+
 | 1006 | C++ | LATHA | ANUP | 350 |
 | 1008 | COMPUTER FUNDAMENTALS | MYTHILI | HIMALAYA | 350 |
 | 1009 | OPERATING SYSTEM | GEETHA | HINDU | 700 |
 | 1003 | DIGITAL ELECTRONICS | RASHMI | HINDU | 400 |
 | 1007 | SOFTWARE ENGINEERING | BHARATHI | SHREE | 600 |
 | 1001 | DATA STRUCTURES | SRIKANTH | SKYWARD | 225 |
 | 1005 | COMPUTER NETWORKS | GEETHA | SKYWARD | 200 |
 | 1004 | UNIX | VIDYA | SKYWARD | 300 |
 | 1002 | DBMS | ASHWINI | SKYWARD | 200 |
 | 1010 | SYSTEM PROGRAMMING | MYTHILI | SKYWARD | 250 |
 +--------+---------------------------------------+------------+-----------+-------+
 10 rows in set (0.09 sec)
ORDER BY
Display book details in descending order of PUBISHER
 SELECT * FROM BOOK
 ORDER BY PUBLISHER DESC;
 +--------+-----------------------------------+---------------+---------------+-------+
 | bookid | title | author | publisher | price |
 +--------+-----------------------------------+---------------+----------------+-------+
 | 1001 | DATA STRUCTURES | SRIKANTH | SKYWARD | 225 |
 | 1010 | SYSTEM PROGRAMMING | MYTHILI | SKYWARD | 250 |
 | 1005 | COMPUTER NETWORKS | GEETHA | SKYWARD | 200 |
 | 1004 | UNIX | VIDYA | SKYWARD | 300 |
 | 1002 | DBMS | ASHWINI | SKYWARD | 200 |
 | 1007 | SOFTWARE ENGINEERING | BHARATHI | SHREE | 600 |
 | 1003 | DIGITAL ELECTRONICS | RASHMI | HINDU | 400 |
 | 1009 | OPERATING SYSTEM | GEETHA | HINDU | 700 |
 | 1008 | COMPUTER FUNDAMENTALS | MYTHILI | HIMALAYA | 350 |
 | 1006 | C++ | LATHA | ANUP | 350 |
 +--------+-------------------------------------+--------------+-----------------+-------+
 10 rows in set (0.00 sec)
GROUP BY CLAUSE
 We can divide the table of information into
smaller groups using the GROUP BY clause.
 We can then use the group function to return
summary information for each group.
 If we want to find maximum price, minimum
price of the book for each publisher, then we
can use the GROUP BY clause based on
PUBLISHER and code is given below:
 There are totally five groups for each group
we get the aggregate data.
SELECT PUBLISHER, MAX(PRICE), MIN(PRICE),
SUM(PRICE) FROM BOOK GROUP BY PUBLISHER;
 Here how this SELECT statement, containing a GROUP BY clause is
evaluated.
 The SELECT clause specifies the columns to be retrieved as follows
 Publisher column in the BOOK table
 The minimum and maximum price in the group that we specified in
the GROUP BY Clause.
 The FROM clause specified the tables that the database must access:
the BOOK table.
 The WHERE clause specifies the rows to be retrieved. Because there
is no WHERE clause all rows are retrieved by default.
 The GROUP BY clause specifies how the rows should be grouped. The
rows are grouped by PUBLISHER, so the MAX, MIN and SUM functions
that is applied to the PRICE Column.
SELECT PUBLISHER, MAX(PRICE), MIN(PRICE),
SUM(PRICE) FROM BOOK GROUP BY PUBLISHER;
 SELECT PUBLISHER, MAX(PRICE), MIN(PRICE), SUM(PRICE) FROM BOOK
 GROUP BY PUBLISHER;
 +----------------+----------------+---------------+----------------+
 | PUBLISHER | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) |
 +---------------+-----------------+---------------+----------------+
 | ANUP | 350 | 350 | 350 |
 | HIMALAYA | 350 | 350 | 350 |
 | HINDU | 700 | 400 | 1100 |
 | SHREE | 600 | 600 | 600 |
 | SKYWARD | 300 | 200 | 1175 |
 +--------------+-----------------+----------------+---------------+
 5 rows in set (0.00 sec)

More Related Content

PDF
Data Love Conference - Window Functions for Database Analytics
PDF
Mysqlfunctions
PDF
MySQL-commands.pdf
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
PPTX
Lab3 aggregating data
PDF
Introduction to oracle functions
DOCX
Database Query Using SQL_ip.docx
PDF
Fulltext engine for non fulltext searches
Data Love Conference - Window Functions for Database Analytics
Mysqlfunctions
MySQL-commands.pdf
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Lab3 aggregating data
Introduction to oracle functions
Database Query Using SQL_ip.docx
Fulltext engine for non fulltext searches

Similar to MYSQL GROUP FUNCTION.pptx (20)

PPT
Module03
ODP
PPT
DOC
ORACLE NOTES
PPTX
SQL.pptx
PPTX
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
PPTX
СУБД осень 2012 Лекция 3
ODP
Mysql1
PPTX
Optimizing queries MySQL
PDF
The Magic of Window Functions in Postgres
 
PDF
Performance Enhancements In Postgre Sql 8.4
PPTX
SQL Keywords
PPT
PPT
Basic Commands using Structured Query Langauage(SQL)
PPT
SQL5.ppt
PPT
PPT
PPTX
aggregatefunction-220420051702.pptx aggregate
PDF
Oracle sql functions
Module03
ORACLE NOTES
SQL.pptx
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
СУБД осень 2012 Лекция 3
Mysql1
Optimizing queries MySQL
The Magic of Window Functions in Postgres
 
Performance Enhancements In Postgre Sql 8.4
SQL Keywords
Basic Commands using Structured Query Langauage(SQL)
SQL5.ppt
aggregatefunction-220420051702.pptx aggregate
Oracle sql functions
Ad

More from kumarkaushal17 (20)

PPTX
RM 4 UNIT.pptx
PPTX
Open Source Cloud Computing (1).pptx
PPTX
Chat application firebase.pptx1.pptx
PPTX
5 UNIT RM.pptx
PPTX
todd-ncts-2011-110828224616-phpapp02 (1).pptx
PPTX
osi-security-architectureppt.pptx
PPTX
Microservice.pptx
PPTX
DOC-20230427-WA0009..pptx
PPTX
DOC-20230427-WA0010..pptx
PPTX
DOC-20230427-WA0012..pptx
PPTX
Semiservice.pptx
PPTX
4. OPTIMIZATION NN AND FL.pptx
PPTX
Cloud_Deployment_Model (1).pptx
PPTX
pending-1664760315-2 knowledge based agent student.pptx
PPTX
pending-1664760315-2 knowledge based agent student.pptx
PPT
cs344-lect4-logic-14jan08.ppt
PPTX
dbmspresentation-161126155322.pptx
PPTX
DS MOD2 (1) (1).pptx
PPTX
IPv4-ppt.k.pptx
PPTX
module 3-.pptx
RM 4 UNIT.pptx
Open Source Cloud Computing (1).pptx
Chat application firebase.pptx1.pptx
5 UNIT RM.pptx
todd-ncts-2011-110828224616-phpapp02 (1).pptx
osi-security-architectureppt.pptx
Microservice.pptx
DOC-20230427-WA0009..pptx
DOC-20230427-WA0010..pptx
DOC-20230427-WA0012..pptx
Semiservice.pptx
4. OPTIMIZATION NN AND FL.pptx
Cloud_Deployment_Model (1).pptx
pending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptx
cs344-lect4-logic-14jan08.ppt
dbmspresentation-161126155322.pptx
DS MOD2 (1) (1).pptx
IPv4-ppt.k.pptx
module 3-.pptx
Ad

Recently uploaded (20)

PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPT
Total quality management ppt for engineering students
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Feature types and data preprocessing steps
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Design Guidelines and solutions for Plastics parts
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
communication and presentation skills 01
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PPTX
introduction to high performance computing
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
August -2025_Top10 Read_Articles_ijait.pdf
Total quality management ppt for engineering students
distributed database system" (DDBS) is often used to refer to both the distri...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Feature types and data preprocessing steps
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Categorization of Factors Affecting Classification Algorithms Selection
Design Guidelines and solutions for Plastics parts
737-MAX_SRG.pdf student reference guides
Amdahl’s law is explained in the above power point presentations
III.4.1.2_The_Space_Environment.p pdffdf
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Abrasive, erosive and cavitation wear.pdf
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
communication and presentation skills 01
Management Information system : MIS-e-Business Systems.pptx
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
introduction to high performance computing

MYSQL GROUP FUNCTION.pptx

  • 2. TYPES OF GROUP FUNCTION  There are different types of Group functions and each of the functions accepts an argument.  The following table identifies the options that can use in the syntax
  • 3. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION
  • 4. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values
  • 5. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to something other than null (count all selected rows using * including duplicate and rows with nulls
  • 6. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to something other than null (count all selected rows using * including duplicate and rows with nulls MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values
  • 7. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to something other than null (count all selected rows using * including duplicate and rows with nulls MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values
  • 8. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to something other than null (count all selected rows using * including duplicate and rows with nulls MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values SUM ( [DISTINCT | ALL ] n) Sum values of n, ignoring null values
  • 9. TYPES OF GROUP FUNCTION GROUP FUNCTION DESCRIPTION AVG (DISTINCT | ALL n) Average value of n, ignoring null values COUNT ( {*|[DISTINCT|ALL] expr}) Number of rows, where expr evaluates to something other than null (count all selected rows using * including duplicate and rows with nulls MAX ([DISTINCT | ALL ] expr ) Maximum value of expr, ignoring null values MIN ( [DISTINCT | ALL ] expr ) Minimum value of expr, ignoring null values STDDEV ( [DISTINCT | ALL ] x ) Standard deviation of n, ignoring null values SUM ( [DISTINCT | ALL ] n) Sum values of n, ignoring null values VARIANCE ( [DISTINCT | ALL ] x) Variance of n, ignoring null values
  • 10. Find the Maximum, Minimum, Sum and Average of price in Book Table  SELECT MAX(PRICE), MIN(PRINCE), SUM(PRICE), AVG(PRICE) FROM BOOK;  +---------------+---------------+----------------+---------------+  | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) | AVG(PRICE) |  +---------------+---------------+----------------+---------------+  | 700 | 200 | 3575 | 357.5000 |  +---------------+---------------+----------------+--------------+  1 row in set (0.00 sec)
  • 11. Find the Maximum, Minimum, Sum and Average of price in SKYWARD Book  SELECT MAX(PRICE), MIN(PRINCE), SUM(PRICE), AVG(PRICE) FROM BOOK WHERE PUBLISHER=‘SKYWARD’;  +---------------+---------------+----------------+---------------+  | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) | AVG(PRICE) |  +---------------+---------------+----------------+---------------+  | 300 | 200 | 1175 | 235 |  +---------------+---------------+----------------+--------------+  1 row in set (0.00 sec)
  • 12. Find out the number of SKYWARD Books present in the book table  SELECT COUNT(*) FROM BOOK WHERE PUBLISHER=‘SKYWARD’;  +-------------+  | COUNT(*) |  +-------------+  | 5 |  +-------------+  1 row in set (0.00 sec)
  • 13. Find out Standard Deviation and Variance of price in book table  SELECT STDDEV(PRICE), VARIANCE(PRICE) FROM BOOK WHERE PUBLISHER=‘SKYWARD’;  +-------------------+----------------------+  | STDDEV(PRICE) | VARIANCE(PRICE) |  +--------------------+----------------------+  | 37.4166 | 1400.0000 |  +--------------------+----------------------+  1 row in set (0.11 sec)
  • 14. ORDER BY Clause  To order of rows that are returned in a query result is undefined.  The ORDER BY Clause can be used to sort the rows.  If we use the ORDER BY clause, it must be the last clause of the SQL statement.  We can specify an expression, an alias or a column position as the sort condition.
  • 15. ORDER BY Clause - Syntax  SELECT <COLUMS> FROM TABLENAME  [ WHERE CONDITION(S) ]  [ ORDER BY { COLUMN, EXPR, NUMERIC POSITION} [ASC | DESC ] ];  ORDER BY: Specifies the order in which the retrieved rows are displayed.  ASC orders the rows in ascending order  DESC orders the rows in descending order
  • 16. ORDER BY Display book details in ascending order of PUBISHER  SELECT * FROM BOOK  ORDER BY PUBLISHER ASC;  +----------+--------------------------------------+----------+---------------+-------+  | book id | title | author | publisher | price |  +-----------+---------------------------------------+----------+--------------+-------+  | 1006 | C++ | LATHA | ANUP | 350 |  | 1008 | COMPUTER FUNDAMENTALS | MYTHILI | HIMALAYA | 350 |  | 1009 | OPERATING SYSTEM | GEETHA | HINDU | 700 |  | 1003 | DIGITAL ELECTRONICS | RASHMI | HINDU | 400 |  | 1007 | SOFTWARE ENGINEERING | BHARATHI | SHREE | 600 |  | 1001 | DATA STRUCTURES | SRIKANTH | SKYWARD | 225 |  | 1005 | COMPUTER NETWORKS | GEETHA | SKYWARD | 200 |  | 1004 | UNIX | VIDYA | SKYWARD | 300 |  | 1002 | DBMS | ASHWINI | SKYWARD | 200 |  | 1010 | SYSTEM PROGRAMMING | MYTHILI | SKYWARD | 250 |  +--------+---------------------------------------+------------+-----------+-------+  10 rows in set (0.09 sec)
  • 17. ORDER BY Display book details in descending order of PUBISHER  SELECT * FROM BOOK  ORDER BY PUBLISHER DESC;  +--------+-----------------------------------+---------------+---------------+-------+  | bookid | title | author | publisher | price |  +--------+-----------------------------------+---------------+----------------+-------+  | 1001 | DATA STRUCTURES | SRIKANTH | SKYWARD | 225 |  | 1010 | SYSTEM PROGRAMMING | MYTHILI | SKYWARD | 250 |  | 1005 | COMPUTER NETWORKS | GEETHA | SKYWARD | 200 |  | 1004 | UNIX | VIDYA | SKYWARD | 300 |  | 1002 | DBMS | ASHWINI | SKYWARD | 200 |  | 1007 | SOFTWARE ENGINEERING | BHARATHI | SHREE | 600 |  | 1003 | DIGITAL ELECTRONICS | RASHMI | HINDU | 400 |  | 1009 | OPERATING SYSTEM | GEETHA | HINDU | 700 |  | 1008 | COMPUTER FUNDAMENTALS | MYTHILI | HIMALAYA | 350 |  | 1006 | C++ | LATHA | ANUP | 350 |  +--------+-------------------------------------+--------------+-----------------+-------+  10 rows in set (0.00 sec)
  • 18. GROUP BY CLAUSE  We can divide the table of information into smaller groups using the GROUP BY clause.  We can then use the group function to return summary information for each group.  If we want to find maximum price, minimum price of the book for each publisher, then we can use the GROUP BY clause based on PUBLISHER and code is given below:  There are totally five groups for each group we get the aggregate data.
  • 19. SELECT PUBLISHER, MAX(PRICE), MIN(PRICE), SUM(PRICE) FROM BOOK GROUP BY PUBLISHER;  Here how this SELECT statement, containing a GROUP BY clause is evaluated.  The SELECT clause specifies the columns to be retrieved as follows  Publisher column in the BOOK table  The minimum and maximum price in the group that we specified in the GROUP BY Clause.  The FROM clause specified the tables that the database must access: the BOOK table.  The WHERE clause specifies the rows to be retrieved. Because there is no WHERE clause all rows are retrieved by default.  The GROUP BY clause specifies how the rows should be grouped. The rows are grouped by PUBLISHER, so the MAX, MIN and SUM functions that is applied to the PRICE Column.
  • 20. SELECT PUBLISHER, MAX(PRICE), MIN(PRICE), SUM(PRICE) FROM BOOK GROUP BY PUBLISHER;  SELECT PUBLISHER, MAX(PRICE), MIN(PRICE), SUM(PRICE) FROM BOOK  GROUP BY PUBLISHER;  +----------------+----------------+---------------+----------------+  | PUBLISHER | MAX(PRICE) | MIN(PRICE) | SUM(PRICE) |  +---------------+-----------------+---------------+----------------+  | ANUP | 350 | 350 | 350 |  | HIMALAYA | 350 | 350 | 350 |  | HINDU | 700 | 400 | 1100 |  | SHREE | 600 | 600 | 600 |  | SKYWARD | 300 | 200 | 1175 |  +--------------+-----------------+----------------+---------------+  5 rows in set (0.00 sec)