SQL 加入更新 table
SQL Join Update table
我有两个表,Table A 有用户 ID 和 5 个不同的产品列(空的,由 count 填充)。 Table 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');
error: You cannot reopen Table_A for update access with member-level
control because Table_A is in use by you in resource environment SQL
我猜您需要相关子查询,而不是一般子查询。也许这就是你想要的:
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'
);
这似乎是一个更合理的查询。
我有两个表,Table A 有用户 ID 和 5 个不同的产品列(空的,由 count 填充)。 Table 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');
error: You cannot reopen Table_A for update access with member-level control because Table_A is in use by you in resource environment SQL
我猜您需要相关子查询,而不是一般子查询。也许这就是你想要的:
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'
);
这似乎是一个更合理的查询。