如何使用 txt 或 csv 文件编写 SQL 查询以从第一行开始更新表列的行?
例如,在更新之前,表格可能看起来像
column_1 column_2
1 null
2 null
3 null
然后更新之后,想要的结果会是这样
column_1 column_2
1 this
2 that
3 those
我试过插入数据,但这只会将其附加到行的底部,而不是替换现有的空值。
使用相同的示例输入,此输出看起来像
column_1 column_2
1 null
2 null
3 null
null this
null that
null those
最佳答案
将数据加载到表中。
然后运行一个带有join
的update
:
update original o
set column_2 = t.column_2
from csv_table t
where o.column_1 = t.column_1;
不过,对于您的示例,截断原始表并将新数据复制到其中可能更有意义。
关于sql - 如何从第一行开始更新表列的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57546720/