05-06-2014 09:07 AM
I have one table A with one variable ID ( for identity ) and another table B, with variables ID, CITY, VAR3, VAR4.
In table A each ID occurs only once.
In table B each ID can have more then one record.
I want the number of ID:s in each CITY. An ID should be counted in each city it occurs, so the total number could be more than the number of individuals in table A.
The result should be presented in a table C, with variables CITY and N, where N = number of individuals in each city.
I think there is no need to use table A.
Do you have any suggestions how to solve this problem?
Thanks for any help.
05-06-2014 09:10 AM
Well, you wouldn't need A as it doesn't add anything. Try:
create table C as
select distinct CITY,
count(ID) as N
group by CITY;
05-06-2014 09:33 AM
true...unless there may be IDs in table B that you don't want counted...or if you needed other attributes on table A that weren't included in B....(assumes facts not in evidence).