簡體   English   中英

Tableau中的SQL JOIN語法錯誤

[英]SQL JOIN Syntax Error in Tableau

我正在編寫一個SQL查詢以連接Tableau(數據分析軟件)中的5個不同表的過程。 Tableau不斷告訴我我的聯接操作中有語法錯誤,我無法弄清楚它可能在哪里。 這是我與自定義SQL查詢一起收到的錯誤:

數據庫錯誤

0x80040E14:JOIN操作中的語法錯誤。

查詢:

SELECT TOP 1 * FROM (

[Attributes$].[Cache] AS [Cache],
[Attributes$].[Design Application] AS [Design Application],
[Attributes$].[Detailed Product Name] AS [Detailed Product Name],
[Attributes$].[Discs] AS [Discs],
[Attributes$].[Drive Height] AS [Drive Height],
[Attributes$].[Form Factor] AS [Form Factor],
[Attributes$].[Heads] AS [Heads],
[Attributes$].[Interface] AS [Interface],
[Attributes$].[Internal Product Name] AS [Internal Product Name],
[Attributes$].[Market Segment Desc] AS [Market Segment Desc],
[Attributes$].[Model] AS [Model1],
[Attributes$].[Product Family Desc] AS [Product Family Desc],
[Attributes$].[Product Mktg Name] AS [Product Mktg Name],
[Attributes$].[Product Type] AS [Product Type],
[Attributes$].[ST Model] AS [ST Model],
[Attributes$].[Sub Market Segment Desc] AS [Sub Market Segment Desc],
[Measures$].[Channel Type] AS [Channel Type],
[Measures$].[Cust Group Desc] AS [Cust Group Desc],
[Measures$].[Cust Sub Group Desc] AS [Cust Sub Group Desc],
[Measures$].[Fiscal Quarter] AS [Fiscal Quarter],
[Measures$].[Fiscal Week] AS [Fiscal Week],
[Measures$].[Fiscal Year] AS [Fiscal Year],
[Measures$].[Model] AS [Model (Measures)],
[Measures$].[Net Revenue] AS [Net Revenue],
[Measures$].[Region] AS [Region],
[Measures$].[Scenario] AS [Scenario],
[Measures$].[Standard Cost Mfg] AS [Standard Cost Mfg],
[Measures$].[Standard Cost Qty] AS [Standard Cost Qty],
[eFBC$].[Model] AS [Model2],
[eFBC$].[Int] AS [Int],
[eFBC$].[FY] AS [FY],
[eFBC$].[Q] AS [Q],
[eFBC$].[eFBC] AS [eFBC],
[Theater$].[Customer Sub Grp Code Numeric] AS [Customer Sub Grp Code Numeric],
[Theater$].[Forecast Region] AS [Forecast Region],
[Encryption$].[Encrypt Type] AS [Encrypt Type],
[Encryption$].[Model] AS [Model3]

FROM ( ( [Attributes$]
  LEFT JOIN [Measures$] ON [Attributes$].[Model] = [Measures$].[Model] )  
  LEFT JOIN [Encryption$] ON [Attributes$].[Model] = [Encryption$].[Model] )
FROM ( ( [Measures$]
  LEFT JOIN [eFBC$] ON ([Measures$].[Model] = [eFBC$].[Model]) AND ([Measures$].[Fiscal Year] = [eFBC$].[FY]) AND ([Measures$].[Fiscal Quarter] = [eFBC$].[Q] ) 
  LEFT JOIN [Theater$] ON ([Measure$].[Cust Sub Group Desc] = [Theater$].[Customer Sub Grp Code Numeric] ) )
FROM ( [eFBC$]
  LEFT JOIN [Encryption$] ON ([eFBC$].Model] = [Encryption$].[Model] ) ) )

) [CustomSQLQuery1]

好。 廣泛的建議。 除非您無法使用Tableau自定義聯接執行所需的操作,並且您完全確定自己在做什么,否則請不要使用Custom SQL。

看來您正在嘗試執行一些非常簡單的LEFT JOIN。 使用Tableau默認工具可以做到這一點,它非常簡單,可拖放,並且非常容易可視化正在發生的事情。 您只需將表拖到工作場所,選擇JOIN的類型和鍵。

回到您的查詢,這是非常錯誤的。 請回到基礎知識並正確處理。 1 SELECT到1 FROM,聽@Turophile。 如果要構建臨時表,則需要更多的SELECT FROM,但是比例始終為1到1。然后猜測,您的示例中不需要它們。

除此之外,您可以選擇*或一一命名字段。

最后,我認為您無法在Tableau自定義查詢上執行TOPX。 這是他們做出的決定,只是在提取數據后才允許對查詢本身進行過濾。 我個人不喜歡該限制,但也不要討厭它。

您的查詢應為(是否為SELECT *,您可以將*替換為您擁有的所有字段名稱文本)

SELECT * FROM [Attributes$]
  LEFT JOIN [Measures$] ON [Attributes$].[Model] = [Measures$].[Model] )  
  LEFT JOIN [Encryption$] ON [Attributes$].[Model] = [Encryption$].[Model] )
  LEFT JOIN [eFBC$] ON [Measures$].[Model] = [eFBC$].[Model] AND [Measures$].[Fiscal Year] = [eFBC$].[FY] AND [Measures$].[Fiscal Quarter] = [eFBC$].[Q] 
  LEFT JOIN [Theater$] ON ([Measure$].[Cust Sub Group Desc] = [Theater$].[Customer Sub Grp Code Numeric]
  LEFT JOIN [Encryption$] ON ([eFBC$].Model] = [Encryption$].[Model]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM