alrwebber Posted August 19, 2010 Share Posted August 19, 2010 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. 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 Quote Link to comment https://forums.phpfreaks.com/topic/211232-i-need-help-on-my-computer-science-project-sql-related/ Share on other sites More sharing options...
BaderEx Posted August 19, 2010 Share Posted August 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211232-i-need-help-on-my-computer-science-project-sql-related/#findComment-1101454 Share on other sites More sharing options...
abdfahim Posted August 20, 2010 Share Posted August 20, 2010 you need to paste your table structure for that Quote Link to comment https://forums.phpfreaks.com/topic/211232-i-need-help-on-my-computer-science-project-sql-related/#findComment-1101502 Share on other sites More sharing options...
kickstart Posted August 20, 2010 Share Posted August 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211232-i-need-help-on-my-computer-science-project-sql-related/#findComment-1101551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.