我正在嘗試編寫一個僅基於選擇查詢的結果插入的MySQL插入。我發現了一些關於在查詢中使用if-then-endIf邏輯的信息,但沒有任何運氣讓人工作。我試圖完成那麼總的思路是這樣的:如果選擇的值插入MySQL> x
if
result of select is > 0
perform insert and select true
else select false
endIf
我想,因爲它似乎像插入超過了預設的限制多,止損的最簡單的方式來運行這種方式。
無論如何,如果有人能指引我如何構建/嵌套陳述的正確方向,我將非常感激。
謝謝。
編輯
的情況下,任何人想知道,這是我結束了:
insert into users_to_classes select ? , ?, 4 from (select class_id, count(*) as students from users_to_classes where participation_level=4 group by class_id) as numUtC, classes where numUtC.class_id=classes.class_id and classes.class_id=? and classes.spaces - ifnull(numUtC.students,0) > 0
它作爲mysqli的預處理語句。再次
感謝您的幫助
請接受我的回答,如果它幫助了你。如果沒有,請添加更多信息,以便我/我們可以進一步幫助您。 – Fellmeister 2011-04-06 01:35:51