SlideShare a Scribd company logo
1 of 20
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

Similar to Group Functions & Aggregate Functions Explained

Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEDrkhanchanaR
 
СУБД осень 2012 Лекция 3
СУБД осень 2012 Лекция 3СУБД осень 2012 Лекция 3
СУБД осень 2012 Лекция 3Technopark
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
The Magic of Window Functions in Postgres
The Magic of Window Functions in PostgresThe Magic of Window Functions in Postgres
The Magic of Window Functions in PostgresEDB
 
Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4HighLoad2009
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functionsVivek Singh
 
Oracle APEX Cheat Sheet
Oracle APEX Cheat SheetOracle APEX Cheat Sheet
Oracle APEX Cheat SheetDimitri Gielis
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)Huda Alameen
 

Similar to Group Functions & Aggregate Functions Explained (20)

Module03
Module03Module03
Module03
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
 
СУБД осень 2012 Лекция 3
СУБД осень 2012 Лекция 3СУБД осень 2012 Лекция 3
СУБД осень 2012 Лекция 3
 
Mysql1
Mysql1Mysql1
Mysql1
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
The Magic of Window Functions in Postgres
The Magic of Window Functions in PostgresThe Magic of Window Functions in Postgres
The Magic of Window Functions in Postgres
 
Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4
 
SQL Keywords
SQL KeywordsSQL Keywords
SQL Keywords
 
Les04
Les04Les04
Les04
 
SQL5.ppt
SQL5.pptSQL5.ppt
SQL5.ppt
 
Les04
Les04Les04
Les04
 
Les05
Les05Les05
Les05
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Oracle APEX Cheat Sheet
Oracle APEX Cheat SheetOracle APEX Cheat Sheet
Oracle APEX Cheat Sheet
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)
 

More from kumarkaushal17

Open Source Cloud Computing (1).pptx
Open Source Cloud Computing (1).pptxOpen Source Cloud Computing (1).pptx
Open Source Cloud Computing (1).pptxkumarkaushal17
 
Chat application firebase.pptx1.pptx
Chat application firebase.pptx1.pptxChat application firebase.pptx1.pptx
Chat application firebase.pptx1.pptxkumarkaushal17
 
todd-ncts-2011-110828224616-phpapp02 (1).pptx
todd-ncts-2011-110828224616-phpapp02 (1).pptxtodd-ncts-2011-110828224616-phpapp02 (1).pptx
todd-ncts-2011-110828224616-phpapp02 (1).pptxkumarkaushal17
 
osi-security-architectureppt.pptx
osi-security-architectureppt.pptxosi-security-architectureppt.pptx
osi-security-architectureppt.pptxkumarkaushal17
 
DOC-20230427-WA0009..pptx
DOC-20230427-WA0009..pptxDOC-20230427-WA0009..pptx
DOC-20230427-WA0009..pptxkumarkaushal17
 
DOC-20230427-WA0010..pptx
DOC-20230427-WA0010..pptxDOC-20230427-WA0010..pptx
DOC-20230427-WA0010..pptxkumarkaushal17
 
DOC-20230427-WA0012..pptx
DOC-20230427-WA0012..pptxDOC-20230427-WA0012..pptx
DOC-20230427-WA0012..pptxkumarkaushal17
 
4. OPTIMIZATION NN AND FL.pptx
4. OPTIMIZATION NN AND FL.pptx4. OPTIMIZATION NN AND FL.pptx
4. OPTIMIZATION NN AND FL.pptxkumarkaushal17
 
Cloud_Deployment_Model (1).pptx
Cloud_Deployment_Model (1).pptxCloud_Deployment_Model (1).pptx
Cloud_Deployment_Model (1).pptxkumarkaushal17
 
pending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxpending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxkumarkaushal17
 
pending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxpending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxkumarkaushal17
 
cs344-lect4-logic-14jan08.ppt
cs344-lect4-logic-14jan08.pptcs344-lect4-logic-14jan08.ppt
cs344-lect4-logic-14jan08.pptkumarkaushal17
 
dbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptxdbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptxkumarkaushal17
 

More from kumarkaushal17 (20)

RM 4 UNIT.pptx
RM 4 UNIT.pptxRM 4 UNIT.pptx
RM 4 UNIT.pptx
 
Open Source Cloud Computing (1).pptx
Open Source Cloud Computing (1).pptxOpen Source Cloud Computing (1).pptx
Open Source Cloud Computing (1).pptx
 
Chat application firebase.pptx1.pptx
Chat application firebase.pptx1.pptxChat application firebase.pptx1.pptx
Chat application firebase.pptx1.pptx
 
5 UNIT RM.pptx
5 UNIT RM.pptx5 UNIT RM.pptx
5 UNIT RM.pptx
 
todd-ncts-2011-110828224616-phpapp02 (1).pptx
todd-ncts-2011-110828224616-phpapp02 (1).pptxtodd-ncts-2011-110828224616-phpapp02 (1).pptx
todd-ncts-2011-110828224616-phpapp02 (1).pptx
 
osi-security-architectureppt.pptx
osi-security-architectureppt.pptxosi-security-architectureppt.pptx
osi-security-architectureppt.pptx
 
Microservice.pptx
Microservice.pptxMicroservice.pptx
Microservice.pptx
 
DOC-20230427-WA0009..pptx
DOC-20230427-WA0009..pptxDOC-20230427-WA0009..pptx
DOC-20230427-WA0009..pptx
 
DOC-20230427-WA0010..pptx
DOC-20230427-WA0010..pptxDOC-20230427-WA0010..pptx
DOC-20230427-WA0010..pptx
 
DOC-20230427-WA0012..pptx
DOC-20230427-WA0012..pptxDOC-20230427-WA0012..pptx
DOC-20230427-WA0012..pptx
 
Semiservice.pptx
Semiservice.pptxSemiservice.pptx
Semiservice.pptx
 
4. OPTIMIZATION NN AND FL.pptx
4. OPTIMIZATION NN AND FL.pptx4. OPTIMIZATION NN AND FL.pptx
4. OPTIMIZATION NN AND FL.pptx
 
Cloud_Deployment_Model (1).pptx
Cloud_Deployment_Model (1).pptxCloud_Deployment_Model (1).pptx
Cloud_Deployment_Model (1).pptx
 
pending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxpending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptx
 
pending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptxpending-1664760315-2 knowledge based agent student.pptx
pending-1664760315-2 knowledge based agent student.pptx
 
cs344-lect4-logic-14jan08.ppt
cs344-lect4-logic-14jan08.pptcs344-lect4-logic-14jan08.ppt
cs344-lect4-logic-14jan08.ppt
 
dbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptxdbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptx
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
IPv4-ppt.k.pptx
IPv4-ppt.k.pptxIPv4-ppt.k.pptx
IPv4-ppt.k.pptx
 
module 3-.pptx
module 3-.pptxmodule 3-.pptx
module 3-.pptx
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 

Group Functions & Aggregate Functions Explained

  • 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)