Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query in sql database

Tags:

sql

mysql

How do we find the top 2 most populated cities i.e where no. of customers are higher than any other


1 Answers

Assuming your schema looks like:

Customers
  -City
  -SSN

You should be able to simply use limit:

select City, count(SSN)
from Customers
group by City
order by count(SSN) desc
limit 2
like image 92
Ian Henry Avatar answered Sep 05 '26 11:09

Ian Henry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!