SQL作为IF语句的结果返回一个字符串

时间:2014-12-08 05:38:44

标签: mysql sql select if-statement case

我的数据库中有以下表格:

enter image description here

我想编写一个具有以下逻辑的SQL查询:

IF QUIZZES<3, RETURN 'INCOMPLETE' ELSE 'COMPLETE'

如何制定查询?

由于

2 个答案:

答案 0 :(得分:3)

您可以使用CASE...ELSE...ENDIF Statement

试试这个:

SELECT (CASE WHEN QUIZZES < 3 THEN 'INCOMPLETE' ELSE 'COMPLETE' END) QuizStatus 
FROM tableA;

SELECT IF(QUIZZES < 3, 'INCOMPLETE', 'COMPLETE') QuizStatus 
FROM tableA;

答案 1 :(得分:1)

select Name,STUDENT_ID,if(QUIZZES<3,'INCOMPLETE','COMPLETE') AS Status from table