Assuming that your tables are respectively named table1
, table2
and table3
, one can do:
SELECT Question_ID, Option_ID, SUM(Vote)
FROM table1 LEFT JOIN table2 USING (Option_ID)
GROUP BY Question_ID, Option_ID
Pregunta
how can I create a script to calculate the voting results for each option knowing that sometimes a question can have up to 4 options?
Solución
Assuming that your tables are respectively named table1
, table2
and table3
, one can do:
SELECT Question_ID, Option_ID, SUM(Vote)
FROM table1 LEFT JOIN table2 USING (Option_ID)
GROUP BY Question_ID, Option_ID