SQL Join Update表

时间:2015-10-19 11:22:16

标签: sql proc-sql

我有两个表,表A有用户ID和5个不同的产品列(空,按计数填充)。表B具有时间戳用户ID和产品ID(在时间t购买)。此代码ID给出错误

update table_A as table_A 
  set Count_Product_1 = (select count(product_ID)
                         from Table_B inner join Table_A 
                           on Table_A.User_ID=Table_B.User_ID 
                         where Product_ID = 'Unique_identifier_product_1');
  

错误:您无法使用成员级别重新打开Table_A以进行更新访问   控制因为您在资源环境SQL

中使用了Table_A

1 个答案:

答案 0 :(得分:3)

我猜你想要一个相关的子查询,而不是一般的子查询。也许这就是你想要的:

update table_A as a 
    set Count_Product_1 = (select count(b.product_ID)
                           from Table_B b
                           where a.User_ID = b.User_ID and
                                 b.Product_ID = 'Unique_identifier_product_1'
                          );

这似乎是一个更合理的查询。

相关问题