[英]LEFT JOIN on two tables
我根据PowerPivot手册中的说明尝试了以下SQL查询以将数据从数据库加载到PowerPivot模型:
SELECT
Production_Product.Name AS Product,
Production_ProductCategory.Name AS Category,
Production_ProductSubcategory.Name AS SubCategory
FROM
Production_Product
LEFT OUTER JOIN Production_ProductSubcategory
ON Production_Product.ProductSubcategoryID = Production_ProductSubcategory.ProductSubcategoryID
LEFT OUTER JOIN Production_ProductCategory
ON Production_ProductSubcategory.ProductCategoryID = Production_ProductCategory.ProductCategoryID
不幸的是,它不断抛出语法错误(缺少运算符),我找不到发生了什么问题。 它仅需一个(第一个)内部联接即可完美运行。
由于您尚未指定RDBMS,因此我认为它是MS Access
因为查询的语法是标准SQL,并且对于所有RDBMS(MS访问除外)都是正确的,所以您必须在Access中用括号将多个LEFT JOIN括起来
SELECT
Production_Product.Name AS Product,
Production_ProductCategory.Name AS Category,
Production_ProductSubcategory.Name AS SubCategory
FROM
((Production_Product
LEFT OUTER JOIN Production_ProductSubcategory
ON Production_Product.ProductSubcategoryID = Production_ProductSubcategory.ProductSubcategoryID)
LEFT OUTER JOIN Production_ProductCategory
ON Production_ProductSubcategory.ProductCategoryID = Production_ProductCategory.ProductCategoryID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.