I have multiple columns that have the name of a sport and a FLOAT value that acts as a percentage of how much one likes the sport.
For example,
Table: likes
Field A: Soccer (94.27 %)
Field B: Football (64.21 %)
Field C: Baseball (1.52 %)
I want to search the fields for the highest percentage, and then return the name of the favorite sport. In this case, it would return 'soccer'.
I have the following MySQL script that retrieves the highest percentage.
-- Get favorite sport (soccer, 94.2716%)
SELECT GREATEST(likes_soccer, likes_football, likes_baseball, likes_basketball, likes_gymnastics,
likes_volleyball, likes_running, likes_swimming, likes_karate, likes_biking, likes_wrestling, likes_golf) AS FAVORITE_SPORT
FROM likes l
WHERE l.child_id = 32;
However, this isn't exactly what I want. But it does output soccer as having 94.27%, which is the highest percentage. However, I am wanting this to return 'soccer', as well as a string representation for any of the other sports. How can I accomplish this?