内部连接不明确的语法

Inner Join Ambiguous Syntax

我对 SQL 不是很熟悉,但我了解基础知识。我最近试图将一些逻辑表单报告复制到 SQL Server 2012。我从 Webi(一种报告工具)的自定义查询开始,并试图在 SQL 中从中创建一个视图。

查询如下所示:

SELECT
   dimGlobalSalesAnalysisTbl.globalSalesAnalysisDesc,
   dimGlobalShipDestinationCountryTbl.area,
   dimGlobalShipDestinationCountryTbl.subarea,
   dimGlobalCurrentProductTbl.sbuCodeDesc,
   dimGlobalShipDateVw.shipDayOfWeekDesc,
   sum(factSalesTblVw.globalSalesValue) AS 'Global Sales Value',
 SUM(factSalesTblVw.salesUnitQuantity*GlobalFiles.dimCurrentGTINTbl.unitQty) AS 'Sales Unit Quantity'
  FROM
  dimGlobalCookCompaniesTbl INNER JOIN factSalesTblVw ON 
 (dimGlobalCookCompaniesTbl.globalCookCompanyID=factSalesTblVw.globalCookCompanyID)
 INNER JOIN dimGlobalHistProductTbl ON (dimGlobalHistProductTbl.globalHistProductID=factSalesTblVw.globalHistProductID)
 INNER JOIN dimGlobalCurrentProductTbl ON (dimGlobalHistProductTbl.globalCurrentProductID=dimGlobalCurrentProductTbl.globalCurrentProductID)
 INNER JOIN dimGlobalHistShipCustomerTbl ON (factSalesTblVw.globalHistShipCustomerID=dimGlobalHistShipCustomerTbl.globalHistShipCustomerID)
 INNER JOIN dimGlobalCurrentShipCustomerTbl ON (dimGlobalHistShipCustomerTbl.shipCustomerID=dimGlobalCurrentShipCustomerTbl.globalCurrentShipCustomerID)
 ***INNER JOIN dimGlobalCountryTbl dimGlobalShipDestinationCountryTbl ON (dimGlobalCurrentShipCustomerTbl.shipDestCountryDesc=dimGlobalShipDestinationCountryTbl.countryCode)***
 INNER JOIN dimGlobalSalesAnalysisTbl ON (factSalesTblVw.globalSalesAnalysisID=dimGlobalSalesAnalysisTbl.globalSalesAnalysisID)
 INNER JOIN dimGlobalShipDateVw ON (dimGlobalShipDateVw.shipJulianDate=factSalesTblVw.shipDateID)
 INNER JOIN GlobalFiles.dimCurrentGTINTbl ON (GlobalFiles.dimCurrentGTINTbl.curGtinId=factSalesTblVw.GtinID)

WHERE
 (
   dimGlobalShipDateVw.shipYearNumber  IN (DATEPART(yy,GETDATE())-1)
   AND
   dimGlobalCurrentShipCustomerTbl.shipCustomerNumberDesc
   IN  ( 'JPC000222-3','CNC000012-1'  )
   AND
  dimGlobalSalesAnalysisTbl.globalSalesAnalysisDesc  =  'Return Credits'
 )
GROUP BY
dimGlobalShipDateVw.shipDate, 
dimGlobalSalesAnalysisTbl.globalSalesAnalysisDesc, 
dimGlobalShipDestinationCountryTbl.area, 
dimGlobalShipDestinationCountryTbl.subarea, 
dimGlobalCurrentProductTbl.sbuCodeDesc, 
Upper(dimGlobalCurrentProductTbl.familyCodeDesc), 
dimGlobalShipDateVw.shipYearNumber, 
dimGlobalShipDateVw.shipDayOfWeekDesc, 
dimGlobalCurrentProductTbl.madeByAbbr, 
dimGlobalCookCompaniesTbl.companyDesc

如果在相关数据库中 运行,此特定查询将在生产系统上运行。当试图在不同的数据库中查看此查询时,我在对象前面加上 [database_name].[schema/dbo] 名称。

在 运行 查询中,我收到错误:

Invalid object name 'WWS.dbo.dimGlobalShipDestinationCountryTbl'

我试图在数据库中找到这个特定的 table,但它不存在,尽管将鼠标悬停在查询中的 table 名称上给出了 table 定义但没有脚本。

这个 table 出现在一个看起来很奇怪的内部连接(第 6 个内部连接)语法中,如下所示:

INNER JOIN dimGlobalCountryTbl dimGlobalShipDestinationCountryTbl ON (dimGlobalCurrentShipCustomerTbl.shipDestCountryDesc=dimGlobalShipDestinationCountryTbl.countryCode)

两个问题: 1.有人可以解释一下内部连接的查询语法吗? 2. 这很愚蠢,但是关于如何查看可能隐藏的 table 定义有什么想法吗?

两个问题:1.有人可以解释一下内连接的查询语法吗?

本例中的内部连接只不过是一个 table 别名。查询的创建者认为别名 table 比实际的 table 名称更容易理解,或者相同的 table 被引用两次并且必须有别名.

2。这非常愚蠢,但是关于如何查看可能隐藏的 table 定义的任何想法? 为什么?我认为当您添加 database_name.schema 语法时,您的 SQL 只是有一个语法错误。

将 table 别名视为列别名....但就像列一样,您可以省略 'AS' 关键字...

dimGlobalCountryTbl dimGlobalShipDestinationCountryTbl 等同于

dimGlobalCountryTbl AS dimGlobalShipDestinationCountryTbl