I am using mysql for survey answers. the schema of the survey table is as follows:
id | rating1 | rating2 | rating3 | rating4 | .... | rating20 |
1 10 10 2 8 .... 4
2 8 8 8 5 .... 7
As you can see, there's rating scores (from 1 to 10) inserted into rating1 - rating20 fields.
I can easily find biggest or smallest scores from rating(1-20) fields for each row using this query: "SELECT greatest(rating1, rating2 .. rating20) FROM TBL_SURVEY WHERE id=1" which returns 10 for id 1.
But I don't know that greatest score belongs which field. And I like to count distnct rating scores. How many 10s or any other scores from rating1-rating20 fields for id 1?
Is there mysql queries for this? or Is there a way to get what I want using php?
Any help would be very appreciated...
GREATEST()function is leading you down the wrong path. Get your data into normalized records and your problem becomes much easier.