Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
INSERT INTO table VALUES (NULL, 45, 12, NOW(), SELECT MAX(current_price) + 1 FROM table)
我想插入一行,其“当前价格”等于同一张表的最高价格加 1。我正在SELECT MAX(current_price) + 1 FROM table这样做。
SELECT MAX(current_price) + 1 FROM table
问题是它返回一个错误。 有人可以帮忙吗?
在子查询周围使用括号:
INSERT INTO table VALUES (NULL, 45, 12, NOW(), (SELECT MAX(current_price) + 1 FROM table));
更好的方法来做到这一点:
INSERT INTO table SELECT NULL, 45, 12, NOW(), MAX(current_price) + 1 FROM table;