[英]MySQL 5.7 do math with column and a MAX() value
我有一個從 1 枚舉的列的臨時表。我想獲取另一個表中列的 MAX() 值並將其添加到臨時表中的所有列中。 我用這樣的變量嘗試了它:
SET @cc_maxguid = SELECT MAX(guid) FROM item_instance;
UPDATE tempItems SET guid = guid + @cc_maxguid WHERE owner_guid = '..targetGUID..';
雖然 targetGUID 是從 LUA 腳本的變量中添加的。 響應是: Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MAX(guid) FROM item_instance' at line 1
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MAX(guid) FROM item_instance' at line 1
所以基本上例如這個tempItems
表
guid A B
1 5 6
2 4 7
3 3 8
item_instance
的 MAX(guid) 值為 20 應變為
guid A B
21 5 6
22 4 7
23 3 8
如何調整我的查詢以使其請求並添加 MAX(guid) 值?
當您嘗試更新 MySQL 中的表並在更新標准中使用相同的表時,會發生此錯誤。
SET @cc_maxguid = (SELECT MAX(guid) FROM item_instance);
UPDATE tempItems SET guid = guid + @cc_maxguid WHERE owner_guid = '..targetGUID..';
上面的查詢應該運行良好。 如果您沒有分享查詢的另一部分,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.