我有這個表:如何在更新之前檢查記錄的值?
// 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