SQL: How do I select the name of the oldest person in a city for each city?
-
How do I select the name of the oldest person in a city for each city? Imagine a table with the schema census {name, age, city}. I want to select the name and age of the oldest person in each city. I have tried: SELECT name, max(age) FROM census group by city but I am not sure it's returning the right data.
-
Answer:
Looks right to me. Make sure the age column is a number or integer and *not* a varchar. Sorting integers as strings gets funky. For example 100 comes before 11.
eagle5co... at Yahoo! Answers Visit the source
Other answers
The Bureau never divulges information where a particular individual has a remote chance of being identified. The Bureau can determine the age of the oldest person in a particular city, but if they tell you, somebody is probably going to jail.
Your query is not correct. select c.city, c.name, max_age from census c join ( select city, max(age) max_age from census) x on c.city=x.city and max_age=c.age
Looks right to me too... why do you think that it's wrong? Try: SELECT name, max(age) FROM census ORDER BY max(age)
Related Q & A:
- HOW CAN I CHANGE MY NAME FROM MY ACCOUNT I MADE A MISTAKE?Best solution by Yahoo! Answers
- How do I change the name that shows as my name when I email?Best solution by Yahoo! Answers
- How do I become more social and a fun person?Best solution by Yahoo! Answers
- How do i hide my name from sending to a recipient?Best solution by Yahoo! Answers
- How can I find pictures of a specific unknown person?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.