基于另一个基于ID的表更新表列

时间:2018-03-15 07:28:54

标签: sql db2

我有2个表'table1'和'table2'。 table1有10,000条记录,table2有5,000条记录。 两个表都有“RECORD_ID”列。 table2中的所有RECORD_ID都可以在table1中找到。

我想根据table1的“RECORD_ID”列更新table2的“PRICE”列。

update  table1 set PRICE = table2.PRICE where RECORD_ID = table2.RECORD_ID

我收到此错误消息:

  

SQL0206N“table2.PRICE”在使用它的上下文中无效   SQLSTATE = 42703

我正在使用DB2。

3 个答案:

答案 0 :(得分:2)

UPDATE table1 SET table1.price = (SELECT table2.price FROM table2 WHERE table2.record_id = table1.record_id)

答案 1 :(得分:1)

你必须使用这样的连接:

UPDATE
Table1
SET
Table1.Column = T2.Column
FROM
Table1 T1
INNER JOIN
Table2 T2
ON 
T1.PK = T2.FK;

答案 2 :(得分:1)

试试这个:

<div class="set-size charts-container">
  <div class="pie-wrapper progress-30">
    <span class="label">30<span class="smaller">%</span></span>
    <div class="pie">
      <div class="left-side half-circle"></div>
      <div class="right-side half-circle"></div>
    </div>
  </div>

  <div class="pie-wrapper progress-60">
    <span class="label">60<span class="smaller">%</span></span>
    <div class="pie">
      <div class="left-side half-circle"></div>
      <div class="right-side half-circle"></div>
    </div>
  </div>

  <div class="pie-wrapper progress-90">
    <span class="label">90<span class="smaller">%</span></span>
    <div class="pie">
      <div class="left-side half-circle"></div>
      <div class="right-side half-circle"></div>
    </div>
  </div>

  <div class="pie-wrapper progress-45 style-2">
    <span class="label">45<span class="smaller">%</span></span>
    <div class="pie">
      <div class="left-side half-circle"></div>
      <div class="right-side half-circle"></div>
    </div>
    <div class="shadow"></div>
  </div>

  <div class="pie-wrapper progress-75 style-2">
    <span class="label">75<span class="smaller">%</span></span>
    <div class="pie">
      <div class="left-side half-circle"></div>
      <div class="right-side half-circle"></div>
    </div>
    <div class="shadow"></div>
  </div>

 
</div>