如何在并行数据仓库中编写多个 table Join 的更新语句?

How to write update statement with multiple table Join in Parallel Data Warehouse?

我在尝试在 TableA 上编写更新语句时遇到困难,在并行数据仓库中加入 TableATableBTableC,但它正在抛出一个例外。

例如:简单示例

Update TableA
Set EnableFlag='Y'

From TableA INNER JOIN TableB ON A.ID=B.ID  
INNER JOIN TableC ON A.ID=C.ID

可能是什么原因造成的?

PDW 上的

UPDATE 有点奇怪,并且有一些限制,如您所见。基本上你需要先做一个CTAS。然后您可以在更新期间加入 CTAS table,或者只是重命名旧的 table 并通过重命名替换为新的 CTAS table。这是 CTAS 的示例,然后在更新期间加入:

CREATE TABLE CTAS_ACS
WITH (DISTRIBUTION = REPLICATE)
AS
SELECT 
 ISNULL(CAST([EnglishProductCategoryName] AS NVARCHAR(50)),0) AS [EnglishProductCategoryName]
,ISNULL(CAST([CalendarYear] AS SMALLINT),0) AS [CalendarYear]
,ISNULL(CAST(SUM([SalesAmount]) AS MONEY),0) AS [TotalSalesAmount]
FROM  dbo.factInternetSales s
JOIN  dbo.DimDate d               ON s.OrderDateKey            = d.DateKey
JOIN  dbo.DimProduct p            ON s.ProductKey              = p.ProductKey
JOIN  dbo.DimProductSubCategory u ON p.[ProductSubcategoryKey] = u.[ProductSubcategoryKey]
JOIN  dbo.DimProductCategory c    ON u.[ProductCategoryKey]    = c.[ProductCategoryKey]
WHERE [CalendarYear] = 2004
GROUP BY [EnglishProductCategoryName]
,        [CalendarYear];

UPDATE AnnualCategorySales
SET   AnnualCategorySales.TotalSalesAmount = CTAS_ACS.TotalSalesAmount
FROM  CTAS_ACS
WHERE CTAS_ACS.[EnglishProductCategoryName] = AnnualCategorySales.[EnglishProductCategoryName]
AND   CTAS_ACS.[CalendarYear]               = AnnualCategorySales.[CalendarYear];

虽然上述模式是典型模式,但在您的情况下,我认为以下模式会起作用(超出我的想象):

Update TableA
Set EnableFlag='Y'
WHERE ID IN (
 SELECT B.ID
 FROM TableB B
 INNER JOIN TableC C ON B.ID=C.ID
)