Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 替换选择中的值_Sql_Postgresql - Fatal编程技术网

Sql 替换选择中的值

Sql 替换选择中的值,sql,postgresql,Sql,Postgresql,我有简单的选择: select id, user_value from some_table 其中,user\u value是一些数字。当用户\u值为0时,我需要将其替换为1。只需使用大小写表达式: select id, (case when user_value = 0 then 1 else user_value end) as user_value from some_table; 如果您想实际更改表中的值,则只需使用带筛选的update: update some_tab

我有简单的选择:

select id, user_value
from some_table

其中,
user\u value
是一些数字。当
用户\u值
为0时,我需要将其替换为1。

只需使用
大小写
表达式:

select id,
       (case when user_value = 0 then 1 else user_value end) as user_value
from some_table;
如果您想实际更改表中的值,则只需使用带筛选的
update

update some_table
    set user_value = 1
    where user_value = 0;