SQL选择和更新命令

时间:2015-07-29 13:56:30

标签: sql

我需要使用update命令更新列。

SELECT * FROM tng_managedobject 
WHERE severity <> 0 
  and class_name like 'Plaza_VES_Junction_Box' 
  and propagate_status <> 0

我需要将所有这些类的propagate_status更新为0.如何使用SQL update命令执行此操作?

谢谢,

7 个答案:

答案 0 :(得分:5)

像这样的简单更新语句就可以了:

CPU0%=0                  CPU0%=30%                   CPU0%=0
CPU1%=100%       or      CPU0%=30%            or     CPU0%=0
CPU2%=0                  CPU0%=30%                   CPU0%=0
CPU3%=0                  CPU0%=30%                   CPU0%=100%

在指定确切的类名时,您不需要update tng_managedobject set propagate_status = 0 WHERE severity <> 0 and class_name = 'Plaza_VES_Junction_Box' and propagate_status <> 0 子句。 LIKE就足够了。

答案 1 :(得分:1)

update tng_managedobject
set propagate_status = 0
where severity <> 0 
and class_name like '%Plaza_VES_Junction_Box%' 
and propagate_status <> 0

对于class_name列,如果您知道确切的名称,最好使用=。如果您要查找包含Plaza_VES_Junction_Box的字符串,请使用%

答案 2 :(得分:1)

UPDATE table1
SET table1.propagate_status = 0
FROM tng_managedobject AS table1
WHERE table1.severity <> 0 
AND table1.class_name like '%Plaza_VES_Junction_Box%' 
AND table1.propagate_status <> 0

答案 3 :(得分:0)

like

正如@zedfoxus指出的那样,您不需要url语句。为了保持答案的不同,请使用他,因为它比我的更有效。

答案 4 :(得分:0)

update tng_managedobject set  propagate_status=0    
where severity <> 0 and class_name like 'Plaza_VES_Junction_Box' 
and propagate_status <> 0

答案 5 :(得分:0)

update tng_managedobject 
set propagate_status = 0 
WHERE severity <> 0 and 
class_name like 'Plaza_VES_Junction_Box' and 
propagate_status <> 0

答案 6 :(得分:0)

你去:

update tng_managedobject 
set propagate_status = 0
WHERE severity <> 0 
  and class_name = 'Plaza_VES_Junction_Box'
  and propagate_status <> 0