0

我在 MS ACCESS 中有以下语句,它检索 0 个数据并且应该检索 1 个值,因为 qselSumPastDivs_vd 检索到 1 个值:

SELECT tblTrades.Tick, 
   IIf([tblTrades].[vd_off]>Now(), [qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],
                                   [qselSumOfPastDivs].[SumOfBBG_Div_Forecast]) AS Expr1
FROM ((tblBbgDivData INNER JOIN 
      tblTrades ON tblBbgDivData.Tick = tblTrades.Tick) INNER JOIN 
      qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) INNER JOIN 
      qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, 
         IIf([tblTrades].[vd_off]>Now(), [qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],
                                         [qselSumOfPastDivs].[SumOfBBG_Div_Forecast]);

是关节产生了问题吗?

我已经删除了 IIF 语句中的 [],但显然,MS ACCESS 需要 () 用于多个 INNER JOIN。还是没有数据...

SELECT tblTrades.Tick, IIf(tblTrades.vd_off>Now(),qselSumPastDivs_vd.SumOfBBG_Div_Forecast,qselSumOfPastDivs.SumOfBBG_Div_Forecast) AS Expr1
FROM ((tblBbgDivData INNER JOIN tblTrades ON tblBbgDivData.Tick = tblTrades.Tick) INNER JOIN qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) INNER JOIN qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, IIf(tblTrades.vd_off>Now(),qselSumPastDivs_vd.SumOfBBG_Div_Forecast,qselSumOfPastDivs.SumOfBBG_Div_Forecast);
4

1 回答 1

1

将 JOIN 从 INNER JOIN 更改为 LEFT JOIN 完成了这项工作:

SELECT tblTrades.Tick, IIf([tblTrades].[vd_off]>Now(),[qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],[qselSumOfPastDivs].[SumOfBBG_Div_Forecast]) AS DivLevel2
FROM ((tblTrades INNER JOIN tblBbgDivData ON tblTrades.Tick = tblBbgDivData.Tick) LEFT JOIN qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) LEFT JOIN qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, IIf([tblTrades].[vd_off]>Now(),[qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],[qselSumOfPastDivs].[SumOfBBG_Div_Forecast]);
于 2013-11-27T16:38:38.977 回答