0

I got a query to calculate the percentage as ,

Select votes, rating, votes/sum(votes) as percentage

But I want to take the values from two different tables. I tried

Select elec.sum(votes) from elec, stat.sum(rating) from stat where year=2009, elec.sum(votes)/tat.sum(rating) as percentage;

This doesn't work.
plz help.

Edited by jrosh: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jrosh
0
SELECT 
  elec.sum(votes) as votes, 
  stat.sum(rating) as rating, 
  votes/rating as percentage 
FROM elec, stat 
WHERE YEAR=2009

Only thing I'm not sure about is the YEAR = 2009 in the where.

1

Following query should work
I m assuming that both table contains year column

select sum(elec.votes)/sum(stat.rating)  as percentage
from elec inner join on elec.year=stat.year
where stat.year=2009
0

Following query should work
I m assuming that both table contains year column

select sum(elec.votes)/sum(stat.rating)  as percentage
from elec inner join on elec.year=stat.year
where stat.year=2009

Yeh. it worked. thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.