Search code examples
mysqldata-extraction

Easy SQL Query Classification


http://i61.tinypic.com/21dexc6.png

I would like to fill the win column with the classifications win or lose with win defined as 1-3 place finish and loss as everything else.


Solution

  • UPDATE table set win = 'lose' WHERE place NOT in (1,2,3);
    UPDATE table set win = 'win' WHERE place in (1,2,3);
    

    OR with a little CASE statement

    UPDATE table set win =  CASE WHEN place IN (1,2,3) THEN 'win' 
                                 WHEN place NOT IN (1,2,3) THEN 'lose' 
                            END ;