sql查询在一个事务中更新单个表的多个列 [英] sql query to update multiple columns of a single table in one transaction
问题描述
我有一个表名"table1"和列名"amount","2001","2002","2003","2004"
该表中有15000条记录.
我在金额"列中有一个浮点值
我必须将2001更新为(2001 =数量* 10/100)
2002年为(2002 =数量* 15/100)
2003年为(2001 =数量* 20/100)
2004年为(2001 =金额* 22/100)
在单个事务中更新所有这些列的代码应该是什么?当我使用以下代码时,我只能更新一列而不是4列
更新"table1"
将2001设置为(2001 =数量* 10/100)
请帮助.
i have a table name "table1" and column name "amount" , "2001", "2002","2003","2004"
there are 15000 records in the table.
i have a float value in column "amount"
i have to update 2001 as ( 2001 = amount *10/100)
2002 as ( 2002 = amount *15/100)
2003 as ( 2001 = amount *20/100)
2004 as ( 2001 = amount *22/100)
what should be the code to update all these columns in a single transaction. when i use the following code, i can update only one column not 4 columns
update "table1"
set 2001 as ( 2001 = amount *10/100)
plz help.
推荐答案
尝试:
UPDATE myTable SET [2001]=amount *10/100, [2002]=amount*15/100
,依此类推.
如何在数据库中应用条件更新
表示
如果年份少于2009年,请更新工资的20%
否则,如果大于2009,则更新工资的15%
如何将其应用到sql服务器查询中,我想开发这样的逻辑
如果年份少于2009年
a = 20%
否则,如果年份大于2009
a = 15%
how to apply conditional update in database
means
if year is less than 2009 update 20% in pay
else if greater than 2009 update 15% in pay
how to apply that in sql server query i want to develop a logic like this way
if year is less than 2009
a = 20%
else if year is greater than 2009
a = 15%
这篇关于sql查询在一个事务中更新单个表的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!