【问题标题】:how to update table using data from another table如何使用另一个表中的数据更新表
【发布时间】:2012-06-03 13:16:39
【问题描述】:

我使用 php 作为我的语言,使用 oracle xe 作为我的数据库。

我有存储item_id,数量的表Order_details。该表目前只保存item_id的数据,而数量有空值。假设项目id是038

我创建了另一个表 order_details2 作为临时表,它具有相同的行,即 item_id,quantity。此表包含 item_id 和数量为 038 和 3 的数据

问题是,我不知道如何使用 order_details2.quantity 中的数据(即 3)使用相同的引用 item_id 将其插入 order_details.quantity

谁能告诉我,我是怎么做到的?我对编程很陌生..

【问题讨论】:

    标签: php oracle-xe


    【解决方案1】:

    如果我正确理解您的要求,那么这样的事情应该可以工作:

    UPDATE
        (SELECT o1.item_id as id1, o1.quantity as qty1, o2.item_id as id2, o2.quantity as qty2
           FROM order_details o1
           JOIN order_details2 o2 on o1.item_id = o2.item_id) t
    SET t.qty1 = t.qty2
    

    您必须小心在任何表中重复的 item_id 值。

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 2019-12-27
      • 2021-01-13
      • 2012-04-07
      • 1970-01-01
      • 2023-03-25
      • 2011-06-29
      • 1970-01-01
      相关资源
      最近更新 更多