Home > Net >  How to replace a value in one temporary column depending on another column mysql using SELECT
How to replace a value in one temporary column depending on another column mysql using SELECT

Time:09-29

Hi so basically this is the table where the newField is just a temporary field that shows up when retrieving it. enter image description here

However what I need to is when I select the table and let's say the mark is greater than 50, the corresponding value under the newField column should be "B" then when greater than 78 should be "A-" and so on...

Thank you!

CodePudding user response:

Use CASE WHEN clause to achieve this

SELECT *, 
    CASE 
        WHEN mark > 50 THEN "A"
        WHEN mark <= 50 THEN "B"
    END AS newField
FROM your_table
  • Related