使用子查询添加数字并在同一个表中更新它。 [英] Add number using subquery and update it in the same table.
本文介绍了使用子查询添加数字并在同一个表中更新它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
字符串 sql = UPDATE table1 SET charge =(从table1中选择费用+20,其中cust_id = 1001)其中cust_id = 1001;
我使用上面的查询在id = 1001的费用中更新20个。但是它给出了错误:
操作必须使用可更新的查询。
我的查询中是否有任何错误。
添加了代码块格式[/ Edit]
解决方案
Whoooo。这个说法很奇怪!
使用此:
更新 table1 SET 费用=费用+ 20 其中 cust_id = 1001
解决方案1是正确的,但有一个更短的方法:
更新 table1 SET 收费+ = 20 其中 cust_id = 1001
String sql = "UPDATE table1 SET charges=(select charges+20 from table1 where cust_id=1001) where cust_id=1001";
I am using query like above to update 20 more in charges where id = 1001. But it is giving error:
"Operation must use an updateable query."
Is there anything wrong in my query.
[Edit]Code block formatting added[/Edit]
解决方案
Whoooo. That statement is weird!
Use this:
UPDATE table1 SET charges=charges+20 where cust_id=1001
Solution 1 is correct, but there's a shorter way:
UPDATE table1 SET charges += 20 where cust_id=1001
这篇关于使用子查询添加数字并在同一个表中更新它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文