I have a MySQL table that contains data from a survey. The survey has about 30 questions and hence at least 30 fields in the table. All the questions are multiple choice and have 5 to 10 possible answers. Now, to generate a report that contains totals of each item (for example if a question "favorite sport" has 10 possible answers, S1, S2,...,S10, I need to know how many people answered S1 as their favorite sport, how many answered S2, and so on. And this I need to do for each field for any given date range.
I am not sure what would be the most efficient way to generate this report. One possibility is to run just one query (SELECT * from Survey WHERE date > abc AND date < xyz), and then run counters inside the while loop for each possible answer. The other way would be to run separate queries for each possible answer (e.g., SELECT sport from Survey WHERE sport='s1') and get [FONT="Courier New"]mysql_num_rows[/FONT]. This seems to be a very long process and just too many queries. Is there any other way to generate this report in a better, faster and more efficient way? Thanks.
A sample report would have info like this:
Q1:
a1=100, b1=120, c1=33, d1=50, e1=0, blank1=30
Q2.:
a2=3, b2=110, c2=12, d2=98, e2=50, blank2=60
...