MS Access:查询添加“If”条件

时间:2016-01-22 10:49:54

标签: mysql ms-access ms-access-2010

我有以下MS Access查询:

SELECT a.*
FROM Version_Change AS a
RIGHT JOIN
  (SELECT VERSION,
          min(ChangeDate) AS minimumdate,
          ObjectID
   FROM Version_Change
   GROUP BY ObjectID,
            VERSION) AS b ON(a.VERSION = b.VERSION)
AND (a.ChangeDate = b.minimumdate)
AND (a.ObjectID = b.ObjectID);

问题是“ChangeDate”列有时可能是空白的。所以我希望我的查询还显示“ChangeDate”为空的字段。如何在查询中集成此条件?

2 个答案:

答案 0 :(得分:1)

如果一个版本和objectid的更改日期全部为NULL,那么min(ChangeDate)也将为空,并且连接将不会成功,因为a.ChangeDate = NULL将被评估为NULL不是真的。

您可以像这样更改ON条件:

ON (a.version = b.version)
   AND
   (
     (a.ChangeDate = b.minimumdate)
     OR
     (a.ChangeDate IS NULL AND b.minimumdate IS NULL)
   )
   AND (a.ObjectID = b.ObjectID);

答案 1 :(得分:0)

你可以使用 Nz 的旧技巧:

Game