这句哪里错了啊,各位高手帮忙解决下啊
6 个解决方案
#1
update s1 set
s1.number = ((select s2.number from stock as s2 where s2.id = 1)+1)
from stock as s1
where s1.id =1
#2
CREATE TABLE s2(id int, number int)
CREATE TABLE stock(id int, number int)
INSERT INTO stock SELECT 1,1
INSERT INTO s2 SELECT 1,2
update stock set number = s2.number+1
FROM s2 WHERE s2.id=1 AND stock.id=1
SELECT * FROM stock
id number
----------- -----------
1 3
update的表本身不能取别名
#3
update stock set number = (number+1) where s1.id =1
#4
update stock set number = (number+1) where id =1
#5
update stock set number = number+1 where id =1
1楼只有在楼主的代码上修正语法
#6
谢谢各位了啊
#1
update s1 set
s1.number = ((select s2.number from stock as s2 where s2.id = 1)+1)
from stock as s1
where s1.id =1
#2
CREATE TABLE s2(id int, number int)
CREATE TABLE stock(id int, number int)
INSERT INTO stock SELECT 1,1
INSERT INTO s2 SELECT 1,2
update stock set number = s2.number+1
FROM s2 WHERE s2.id=1 AND stock.id=1
SELECT * FROM stock
id number
----------- -----------
1 3
update的表本身不能取别名
#3
update stock set number = (number+1) where s1.id =1
#4
update stock set number = (number+1) where id =1
#5
update stock set number = number+1 where id =1
1楼只有在楼主的代码上修正语法
#6
谢谢各位了啊