【问题标题】:MS Access SQL multiple JOIN and WHERE clausesMS Access SQL 多个 JOIN 和 WHERE 子句
【发布时间】:2014-02-26 18:32:10
【问题描述】:

我正在尝试将多个表连接到一个名为“Claims”的主表(代码如下) 三张表有以下条件

  1. [NYS Medicaid Fee Schedule Jan12] 具有重复键,并且必须选择正确的记录,其中主表中的值介于查找表中的两个日期之间
  2. [NYS Medicaid Fee Schedule Apr13] 具有重复键,并且必须选择正确的记录,其中主表中的值介于查找表中的两个日期之间
  3. [NY Medicare] 有重复的键,必须将“区域”视为第二级才能选择正确的记录

当我只使用一个 WHERE 子句时,查询有效并且没有问题。为单独的表添加 1 个或两个额外的 WHERE 条件会导致麻烦。

我在互联网上进行了大量研究,发现括号对 ACCESS 非常重要。我看到了有关多个连接的正确语法的示例,但没有看到针对特定表的带有 WHERE 子句的多个连接。

我希望我只是误解了如何放置括号。


FROM ( ( ( ( ( ( [Claims]  
LEFT JOIN [BillType] ON [Claims].[Bill_Type] = [BillType].[BillType_Bill Type Key] )  
LEFT JOIN [PlaceofService] ON [Claims].[Place_of_Service] = [PlaceofService].[POS_Place of Service] )  
LEFT JOIN [Participating] ON [Claims].[TIN] = [Participating].[TIN] )  
LEFT JOIN [NYS Medicaid Fee Schedule Apr11] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr11].[Apr11_NYS_CODE] )  
LEFT JOIN [NYS Medicaid Fee Schedule Jan12] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_CODE]  
  WHERE [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_END DATE] )  
LEFT JOIN [NYS Medicaid Fee Schedule Apr13] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_CODE]    
  WHERE [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_END DATE] )  
LEFT JOIN [NY Medicare] ON [Claims].[FivedigitProcCode] = [NY Medicare].[MEDICARE_HCPCS CODE]  
  WHERE [Claims].[Zone] = [NY Medicare].[MEDICARE_ZONE]  

【问题讨论】:

    标签: sql ms-access join where parentheses


    【解决方案1】:

    一个 SQL 查询只有一个 where 子句。您应该将这些条件更改为 on 条件的一部分:

    FROM ( ( ( ( ( ( [Claims]  
    LEFT JOIN [BillType] ON [Claims].[Bill_Type] = [BillType].[BillType_Bill Type Key] )  
    LEFT JOIN [PlaceofService] ON [Claims].[Place_of_Service] = [PlaceofService].[POS_Place of Service] )  
    LEFT JOIN [Participating] ON [Claims].[TIN] = [Participating].[TIN] )  
    LEFT JOIN [NYS Medicaid Fee Schedule Apr11] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr11].[Apr11_NYS_CODE] )  
    LEFT JOIN [NYS Medicaid Fee Schedule Jan12] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_CODE]  
      AND [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_END DATE] )  
    LEFT JOIN [NYS Medicaid Fee Schedule Apr13] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_CODE]    
      AND [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_END DATE] )  
    LEFT JOIN [NY Medicare] ON [Claims].[FivedigitProcCode] = [NY Medicare].[MEDICARE_HCPCS CODE]  
      AND [Claims].[Zone] = [NY Medicare].[MEDICARE_ZONE]  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多