我的数据库中有以下表格:
我想编写一个具有以下逻辑的SQL查询:
IF QUIZZES<3, RETURN 'INCOMPLETE' ELSE 'COMPLETE'
如何制定查询?
由于
答案 0 :(得分:3)
您可以使用CASE...ELSE...END或IF 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