【问题标题】:How to set values for one column based on another?如何根据另一列设置一列的值?
【发布时间】:2020-07-08 19:17:23
【问题描述】:

如何根据另一列设置一列的值?

目标:当 DB 表中的列 Remote = table SO 中的列 Thrunode -> 在表 DB 中设置列​​ customer = table SO

DB = tbl_db_collecting
SO = tb_systemshc

sql:

UPDATE tbl_db_collecting SET
    tbl_db_collecting.customer = tb_systemshc.environment
FROM tb_systemshc
WHERE tbl_db_collecting.lower(remote) = tb_systemshc.lower(thrunode)

输出:

SQL Error [3F000]: ERROR: schema "tbl_db_collecting" does not exist

【问题讨论】:

    标签: postgresql join sql-update


    【解决方案1】:

    这是你要找的吗?

    update tbl_db_collecting
       set customer = tb_systemshc.environment
      from tb_systemshc
     where lower(tbl_db_collecting.remote) = lower(tb_systemshc.thrunode);
    

    当您编写 tbl_db_collecting.lower(remote) 时,PostgreSQL 会解析它,就好像您正在寻找架构 tbl_db_collecting 中定义的 lower() 函数一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-16
      • 2019-11-02
      • 2018-09-09
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多