Sie sind auf Seite 1von 6

Aggregate Functions

Prof. Hasso Plattner


Facts about
Aggregate Functions
! AggregaLe luncuons (Al) work on daLa seLs lnsLead of slngle
values
! PAvlnC clause lncludes predlcaLes Lo lLer resulL seL of
aggregaLe funcuons
! SCL-SynLax:
SLLLC1 Al(aurlbuLe1)
l8CM Lable
WPL8L aurlbuLe= value
C8Cu 8? aurlbuLe2, aurlbuLe3
PAvlnC Al(aurlbuLe_name1) > 3

2
SQL Aggregate Functions
! CCun1
! SuM
! Average
! Medlan
! Maxlmum
! Mlnlmum
3
! AggregaLe luncuon CCun1 ls shown on Lhe followlng
example Lable:
Example
reclu fname lname gender clLy counLry blrLhday
0 !ohn SmlLh m Chlcago uSA 12.03.1964
1 Mary 8rown f London uk 12.03.1964
2 !ane uoe f alo AlLo uSA 23.04.1976
3 !ohn uoe m alo AlLo uSA 17.06.1932
4 eLer SchmldL m oLsdam CL8 11.11.1973
. . . . . .
4
COUNT
! CCun1 Lhe number of people per counLry
!"#$%& ()*
++ ,
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
3
COUNT
! CCun1 Lhe number of people per counLry
!"#$%& ()*
++ ,
+> ,
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
6
COUNT
! CCun1 Lhe number of people per counLry
!"#$%& ()*
++ ?
+> ,
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
7
COUNT
! CCun1 Lhe number of people per counLry
!"#$%& ()*
++ >
+> ,
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
8
!"#$%& ()*
++ >
+> ,
+? ,
COUNT
! CCun1 Lhe number of people per counLry
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
9
COUNT
! CCun1 Lhe number of people per counLry
78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
!"#$%& ()*
++ >
+> ,
+? ,
@ @
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
10
COUNT
! CCun1 Lhe number of people per counLry
!"#$%& ()*
++ >
+> ,
+? ,
@ @
A B
!"#$%&
-.$/&01 -34C"/#
DE7 >
DF ,
GH! ,
@ @
SLLLC1 counLry, CCun1(*) AS cluzens
l8CM world_populauon
C8Cu 8? counLry

78039$&" :"-&.0 ;.0 <-.$/&01=
++ +> ++ ++ +? @
-.$/&01 23-4./)01
5)%$"62 5)%$"
. .
42 CL8
43 uk
44 uSA
. .
11

Das könnte Ihnen auch gefallen