我有这个表:如何在更新之前检查记录的值?
// QandA
+----+-----------+-----------------+-------------+------+------+
| id | post | accepted-answer | question_id | let | type |
+----+-----------+-----------------+-------------+------+------+
| 1 | question1 | null | 1 | 200 | 0 |
| 2 | answer1 | null | 1 | null | 1 |
| 3 | answer2 | 1 | 1 | null | 1 |
| 4 | answer3 | null | 1 | null | 1 |
+----+-----------+-----------------+-------------+------+------+
// ^0 = question | 1 = answer
我也有这个疑问:
// this query changes accepted answer
UPDATE QandA
SET accepted_answer = IF(id <> :id, NULL, 1)
WHERE question_id = :question_id;
现在我想要在更新前检查let
领域。这样的事情:
if (`let` is null) then {update here}
else {don't update}
where `question_id` = :question_id and `type` = 0
我怎么能在MySQL中做到这一点?
你可以在哪里添加''和'let'为null''吗? – Kateract
@Kateract emm,似乎是正确的,我认为这是更难..无论如何谢谢你,我会尝试它。 – stack