
October 2nd, 2007, 06:35 PM
|
|
Registered User
|
|
Join Date: Sep 2007
Posts: 7
Time spent in forums: 1 h 47 m 25 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by clem_c_rock Hello,
trying to calculate the percentages of artist's from each country in our database.
I am drawing from 2 tables, the artists table which has a short country code and the citylatlong table which has the full country name.
Since the artists.country column is a varchar(2), is it possible to get the number of artists per country as a percentage.
Here's the query I'm trying:
SELECT artists.id, artists.country, countries.countryLONG, (SUM( artists.country ) / COUNT(artists.country )) *100 percentage FROM artists inner join (select countrySHORT, countryLONG from citylatlong GROUP BY countrySHORT, countryLONG) countries ON artists.country = countries.countrySHORT GROUP BY country ORDER BY country ASC limit 10 ;
The percentage column always comes out as 0.
Any ideas?
Thanks,
Clem c |
Hi Clem, have you tried casting artists.country column like this:
cast(artists.country as decimal)
in such way, it will be a valid divisor.
|