2015-10-19 68 views
0

我有兩個表,表A有用戶標識和5個不同的產品列(空的,以count填充)。表B有時間戳用戶標識和產品標識(在時間t購買)。此代碼ID給錯誤SQL加入更新表

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

+0

SAS環境 –

回答

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' 
         ); 

這似乎是一個更合理的查詢。

+0

謝謝它的工作,但我的表有400,000+條記錄,所以它在(SAS環境)的服用時間,結果等待。 –

+0

'table_B(user_id,product_id)'上的索引將有助於加快查詢速度。 –