SELECT with CASE or IF

suggest change

Query

SELECT st.name,
       st.percentage, 
       CASE WHEN st.percentage >= 35 THEN 'Pass' ELSE 'Fail' END AS `Remark` 
FROM student AS st ;

Result

+--------------------------------+
|   name   | percentage | Remark |
+--------------------------------+
|   Isha   |     67     |  Pass  |
|   Rucha  |     28     |  Fail  |
|   Het    |     35     |  Pass  |
|   Ansh   |     92     |  Pass  |
+--------------------------------+

Or with IF

SELECT st.name,
       st.percentage, 
       IF(st.percentage >= 35, 'Pass', 'Fail') AS `Remark` 
FROM student AS st ;

N.B

IF(st.percentage >= 35, 'Pass', 'Fail')

This means: if st.percentage >= 35 is true, return 'Pass', otherwise return 'Fail'. A NULL percentage is not >= 35, so the result is 'Fail'.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents