子查询 - IIF()4 INNER JOIN

时间:2013-11-27 15:37:11

标签: sql ms-access subquery inner-join iif

我在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);

1 个答案:

答案 0 :(得分:1)

将JONER从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]);