我有4个桌子我正在参加Adventureworks 2012.我无法弄清楚为什么我得到'无法绑定错误'.
Msg 4104,Level 16,State 1,Line 7
无法绑定多部分标识符"Production.ProductCategory.Name".
消息4104,级别16,状态1,第1行
无法绑定多部分标识符"Production.ProductCategory.Name".
SELECT COUNT(WorkOrderID) AS TotalWorkOrders, [Production].[ProductCategory].[Name] FROM [Production].[WorkOrder] WO INNER JOIN [Production].[Product] P ON WO.[ProductID] = P.[ProductID] INNER JOIN [Production].[ProductSubcategory] PS ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID] INNER JOIN [Production].[ProductCategory] PC ON PC.[ProductCategoryID] = PS.[ProductCategoryID] WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02' GROUP BY [Production].[ProductCategory].[Name]
Gordon Linof.. 5
您的查询已为表提供 [Production].[ProductCategory]
了别名PC
.您需要在查询的其余部分中使用它:
SELECT COUNT(WO.WorkOrderID) AS TotalWorkOrders, PC.[Name] FROM [Production].[WorkOrder] WO INNER JOIN [Production].[Product] P ON WO.[ProductID] = P.[ProductID] INNER JOIN [Production].[ProductSubcategory] PS ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID] INNER JOIN [Production].[ProductCategory] PC ON PC.[ProductCategoryID] = PS.[ProductCategoryID] WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02' GROUP BY PC.[Name];
为表提供别名后,需要引用该别名而不是原始表名.
您的查询已为表提供 [Production].[ProductCategory]
了别名PC
.您需要在查询的其余部分中使用它:
SELECT COUNT(WO.WorkOrderID) AS TotalWorkOrders, PC.[Name] FROM [Production].[WorkOrder] WO INNER JOIN [Production].[Product] P ON WO.[ProductID] = P.[ProductID] INNER JOIN [Production].[ProductSubcategory] PS ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID] INNER JOIN [Production].[ProductCategory] PC ON PC.[ProductCategoryID] = PS.[ProductCategoryID] WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02' GROUP BY PC.[Name];
为表提供别名后,需要引用该别名而不是原始表名.