将表中所有列的所有零(如果有)更改为...说1 [英] Changing all zeros (if any) across all columns (in a table) to... say 1
本文介绍了将表中所有列的所有零(如果有)更改为...说1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张18列(全部为Ints)和1040行的表。如果任何值为零,我想将其更改为1。我正在使用Postgresql。做这个的最好方式是什么。我无法提出一个简单的更新声明...而且我是数据库新手。
I have a table with 18 columns (all Ints) and 1040 rows. If any value is zero I want to change it to 1. I am using Postgresql. What is the best way to do this. I cannot come up with a simple update statement... and I am new to DBs.
我应该看的任何指针,以学习如何实现这样的目标……(我想某种脚本,如果Postgresql存在这样的东西。 。)
Any pointers on what I should look at to learn how to achieve something like this... (I would think some sort of script, if such thing exists for postgresql.. I don't know)
谢谢
推荐答案
此
UPDATE table SET columnA = 1 WHERE columnA = 0
但是您将需要为每列查询,或者
But you will need a query for each column, or
UPDATE table SET columnA =
CASE WHEN columnA = 0 THEN 1
ELSE columnA
END,
columnB =
CASE WHEN columnB = 0 THEN 1
ELSE columnB
END, ...
这篇关于将表中所有列的所有零(如果有)更改为...说1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文