使用MS Access COUNT DISTINCT函数

时间:2012-05-25 19:33:56

标签: sql ms-access

以下查询返回RequestDate在RequestDate的60天内的请求数以及各种其他列。

如何在RequestDate的60天内修改代码以计算唯一 AcquisitionDates的数量?我尝试使用COUNT DISTINCT,但无法弄清楚在这种情况下应该如何使用它。

SELECT SceneTable.PATH, SceneTable.ROW, SceneTable.ROW, SceneTable.UlLat,
       SceneTable.UlLon, SceneTable.UrLat, SceneTable.UrLon, SceneTable.LlLat, 
       SceneTable.LlLon, SceneTable.LrLat, SceneTable.LrLon, 
      Sum(Iif((DateDiff("d",[AcquisitionDate],[RequestDate])<60),1,0)) AS Expr1, 
       Count(RequestTable.RequestID) AS CountOfRequestID
FROM ((SceneTable INNER JOIN 
       SceneAcquisitionTable 
           ON SceneTable.SceneID = SceneAcquisitionTable.SceneID) INNER JOIN
       UserSceneAcquisitionTable 
           ON SceneAcquisitionTable.SceneAcquisitionID = 
              UserSceneAcquisitionTable.SceneAcquisitionID) INNER JOIN 
       RequestTable 
           ON UserSceneAcquisitionTable.UserSceneAcquisitionID = 
              RequestTable.UserSceneAcquisitionID
GROUP BY SceneTable.PATH, SceneTable.ROW, SceneTable.UlLat, SceneTable.UlLon, 
         SceneTable.UrLat, SceneTable.UrLon, SceneTable.LlLat, SceneTable.LlLon, 
         SceneTable.LrLat, SceneTable.LrLon

以下是样本表以及预期结果: Here are sample tables as well as expected results:

1 个答案:

答案 0 :(得分:0)

有关在Access

中实施COUNT DISTINCT的一般方法,请参阅this solution