Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
giafortun
Starting Member
1 Post |
Posted - 2010-09-07 : 02:44:57
|
I need to come up with a query that will show the percentage of a certain nationality in a given cityIn a table, these are the given fields:Id number of an individualcity codenationality codethis is the sql code i have so far:select distictrow popdata.citynumcount(*) from popdatawhere popdata.ancnumber=720group by popdata.citynumorder by count(*) desc;-----ancnumber stands for the nationality code, 720 stands for one nationality,for this specific problem 720 means filipinothis sql gives me the number of filipinos in a given city, but i have problem coming up with the total population in a city in another column, and so cant solve the percentagecan anyone please help me? thank you very much!! |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-09-07 : 08:14:37
|
here's one waySELECT MAX(anc) / MAX(total) FROM (SELECT 0 as anc, count(*) as total from popdataunion allSELECT count(*) as anc, 0 as total from popdata where ancnumber = 720) |
 |
|
|
|
|