SQL Grouping ?

  • Thread starter Thread starter dhstein
  • Start date Start date
D

dhstein

This is not the real case - but just for an example:

Assume tblAnimalsinZoo

Fields: Type, Number


Example: Elephant 2
Snake 10
Parrot 4
Turtle 2
Lion 2



tblClassification

Fields Type
Animal

Example: Mammal Elephant
Reptile Snake
Bird Parrot
Mammal Lion
Reptile Turtle


What would the SQL statement be to get the total by type:

Example:

Mammals 4
Reptiles 12
Birds 4

Thanks for any help you can provide on this.
 
dhstein said:
This is not the real case - but just for an example:

Assume tblAnimalsinZoo

Fields: Type, Number


Example: Elephant 2
Snake 10
Parrot 4
Turtle 2
Lion 2



tblClassification

Fields Type
Animal

Example: Mammal Elephant
Reptile Snake
Bird Parrot
Mammal Lion
Reptile Turtle


What would the SQL statement be to get the total by type:

Example:

Mammals 4
Reptiles 12
Birds 4

Thanks for any help you can provide on this.

Select c.[Type],Sum(a.[Number]) As [Total]
FRom tblAnimalsinZoo As a INNER JOIN
tblClassification As c On a.[Type]=c.[Type]
GROUP BY c.[Type]
 
Back
Top