Parag Jadhav Parag Jadhav - 2 months ago 11
SQL Question

Calculate the Poll Result

I have a page from where users can take a poll and submit their response. A poll contains
1. Poll title/Subject
2. Question/Heading (Can be One or more)
3. four options for each question (can select only one option)

The poll response is stored in MySQL table,

  1. id int(11)

  2. poll_headingid int(11)

  3. user_id int(11)

  4. response varchar(50)

  5. subject_id int(11)

I want to calculate that how many percentage of users have submitted a response for each question. I tried to use following query and got following result

enter image description here

Can anyone please help me


Sorry for such basic question, but I figured it out. The correct query was

select response, count(*) / (select count(*) from tbl_parent) * 100 as 
percentage from poll_result 
WHERE response='d' 
AND poll_headingid=12 
AND subject_id=4