Home Finding the city with the max population
Reply: 0

Finding the city with the max population

user513
1#
user513 Published in May 28, 2018, 3:19 am

I have a test table which looks like:

And I want to find the city with the max population. Here is my query:

SELECT City, count(*) AS [Population]
INTO #stats
FROM [Customer]
GROUP BY City

SELECT City, [Population]
FROM #stats
WHERE [Population] = 
(
    SELECT max([Population])
    FROM #stats
)

DROP TABLE #stats

Is it possible to do it in one query, without using a temp table? What would other shorter practical ways be to get that result?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312795 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO