question

Dharmendra avatar image
Dharmendra asked

sql query on 'select within select'

this is table : bbc(name, region, area, population, gdp)

Some countries have populations more than three times that of any of their neighbours (in the same region). Give the countries and regions.

this is what i am trying : select distinct a.name, a.region from bbc a where a.name = any(select b.name from bbc b where a.name!=b.name and a.region=b.region and a.population> 3 * b.population)

but there is still some mistakes, i couldn't find

please try to solve it.

sql-server-2005querymysql
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

are you using mysql or SQL Server 2005 ?
0 Likes 0 ·
Homework or assignment ?
0 Likes 0 ·

1 Answer

· Write an Answer
POLSKA avatar image
POLSKA answered
select x.name,x.region from bbc x where (x.population/3)>(select MAX(y.population) from bbc y where x.region=y.region and y.name != x.name)
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.