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.

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.