Skip to content
Advertisement

SQL bring number of count, another column basis problem [closed]

I have this table:

BANK – BRANCH_NAME – ADDRESS – DISTRICT – CITY – PHONE – FAX – OPENNING DATE

How do I bring branches on a city basis?

enter image description here

What I expect is a city knows how many branches it has.

Advertisement

Answer

From the comments:

what I expect is a city knows how many branches it has

You can use aggregation:

select city, count(*) no_branches from mytable group by city

If (city, branch) tuples are not unique in the table, then:

select city, count(distinct branch) no_branches from mytable group by city
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement