0

我需要进行查询以验证:

if type_answeris equal toMultipla Escolha所以我只需要返回不为空的记录correct_answer_description_id If the type_answeris not equal to Multipla Escolha,不要制定这个规则。

所以,我尝试这种方式:

SELECT * FROM book_unit_question
WHERE book_unit_id = 2 
AND status = false
CASE WHEN type_answer = 'Multipla Escolha' THEN
correct_answer_description IS NOT NULL

但我得到:

ERROR:  syntax error at or near "CASE"
4

2 回答 2

1

我不认为 CASE 是这里最简单的方法。你可以试试下面重写的查询吗?

SELECT * FROM book_unit_question
WHERE book_unit_id = 2 
AND status = false
AND (type_answer is null or type_answer != 'Multipla Escolha' or
correct_answer_description IS NOT NULL)
于 2020-01-22T14:40:02.117 回答
0

摆脱否定产生否定构造“type_answer 不等于 Multipla Escolha,不要制定此规则”,通过改写“类型答案等于 Multipla Escolha 然后应用此规则。同时应用”仅返回正确答案描述 ID 中不为空的记录”。我们到达:

select * 
  from book_unit_question
 where book_unit_id = 2 
   and status = false
   and type_answer = 'Multipla Escolha' 
   and correct_answer_description is not null;
于 2020-01-22T15:24:44.567 回答