Let say, I’ve a table in my database like this be it in POSTGRESQL or MYSQL :-
video_clip_name | bad | so_so | good|
video 1 | 20 | 13 | 3 |
video 2 | 12 | 20 | 33 |
video 3 | 40 | 34 | 33 |
video 4 | 20 | 23 | 13 |
video 5 | 20 | 13 | 37 |
I want to determine which video is rated as bad or so_so or good based on highest score after comparison is made between the three column (bad,so_so and good). Let say, video 1 has bad rating which is higher than the other two columns..this mean that video 1 has been rated as bad.
So my question is how to write such SQL statement in POSTGRESQL/MYSQL to output the overall rating for each video based on comparison between the three columns’ value?
thank you
Here is another way using
CASEexpression. I use SQL Server and not MySQL or PostGreSQL but I think this ANSI SQL compliant. The sample data and output uses various values. However, it they are all equal it currently will pick the rating in the order bad, *so_so* and good.Script:
Output: