Mashiba Sakuto
Mashiba Sakuto

Reputation: 223

How to get number of value based on type?

I have a database:


pID    |type| City     |   
------------------
Z0D12  | Z  | Amsterdam
XOD12  | X  | Paris
YOD12  | Y  | Madrid
GOD12  | G  | Amsterdam
GOD12  | G  | Amsterdam

I have a composite key with a date row so the pID can be a duplicate

I want to display the amount of times a city occurs per type:


City       |type    | amountoftimes |   
------------------
Amsterdam  | Z      | 1
Amsterdam  | G      | 2
Paris      | X      | 1
Madrid     | Y      | 1

How do I do this?

Upvotes: 0

Views: 30

Answers (1)

camba1
camba1

Reputation: 1820

It will be something like:

select citiTable.city, citiTable.type, count(*) as amountOfTimes
from citiTable
group by citiTable.city, citiTable.type

The documentation on how to use count can be found here

Upvotes: 1

Related Questions