Click here to Skip to main content
15,902,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. newbie here.

I am trying to find out how many keys.
For example,
( Animals ) PK ---- ( Enclosure ) Fk
 Gorilla ------------ North
Chimps ------------- North
Dogs --------------- North
Cats -------------- South
Rabbits ------------ East

Here 3 animals are in 1 Enclosure location of the North.
1 animal in South and 1 in East.


How can I count like that, when the database is huge?
is there a command for it?

What I have tried:

i tried using

SQL
Select distinct (animal.enclosure_enclosureID ) from mydb.animals ;


but this shows
all the unique enclosure IDs.
How can I find how many of the animal_ID are related to each of the enclosure ID?
Posted
Updated 4-Dec-21 4:29am
v2
Comments
PIEBALDconsult 4-Dec-21 10:05am    
I don't think you provide enough information.
Use Improve question to add more detail.
Dave Kreskowiak 4-Dec-21 10:23am    
It's not entirely clear what you're asking. "Counting keys" is not a thing.

Are you looking for the total number of animals? The total number of enclosures? The total number of animals in each enclosure? ... What?
Bonzowo 4-Dec-21 10:24am    
Total number of animals in each enclosure. Yeah

1 solution

This is your homework assignment so you're not going to get a straight up answer.

You'll get a hint though. You don't need DISTINCT. You need GROUP BY.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900