Jump to content

I need help on my computer science project! SQL related. :)


Recommended Posts

Below is a partial solution to the challenge to write an SQL query to find to list the US cities that have the highest percentage of Filipinos.

 

34q8uad.gif

 

This will just list the number of people (not the percentage).

 

How do I adapat the fragment code above to show the ff:

a) Two columns - the Filipino Population and the Total Population

b) The Filipino Population as a percentage of the total population

 

Thank you to those who will help :)

Here you go:

 

This query will show the highest 3 cities of Filipinos.

 

num = is the number of Filipinos in a city

pop = is the population

 

SELECT city, num, pop, num/pop, (num/pop)*100 as precentage FROM `cit` order by num/pop DESC LIMIT 3

 

Good Luck

Hi

 

I assume the table POPDATA has one row per member of the population (hence why using COUNT).

 

If so then something like this (not test so excuse any typos).

 

SELECT a.CITYNUM, CityPop, CityFilipinoPop, ((CityFilipinoPop/CityPop)*100) AS CityFilipinoPerc
FROM (SELECT POPDATA.CITYNUM, COUNT(*) AS CityPop
FROM POPDATA
GROUP BY POPDATA.CITYNUM) a
LEFT OUTER JOIN (SELECT POPDATA.CITYNUM, COUNT(*) AS CityFilipinoPop
FROM POPDATA
WHERE POPDATA.ANCNUMBER = 720
GROUP BY POPDATA.CITYNUM) b
ON a.CITYNUM = b.CITYNUM
ORDER BY CityFilipinoPerc

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.