我很难为每个用户返回多个值。我尝试过Select Distinct的变种无济于事。我需要我的代码只返回每个userID一个值。
SELECT Roster.UserID,
EventLog.Type,
IIf([EventLog]![LogType] Like "Acc*" And [EventLog]![Action] Like "Wri*",[EventLog]![Date],Date()-183) AS [Review Date]
FROM EventLog
INNER JOIN Roster
ON EventLog.UserID = Roster.UserID
GROUP BY Roster.UserID,
EventLog.Type,
IIf([EventLog]![LogType] Like "Acc*" And [EventLog]![Action] Like "Wri*",[EventLog]![Date],Date()-183)
HAVING (((EventLog.Type) Like "Att*"));
代码在满足第一个条件时从IIf返回两个值。我怎么能限制一个或另一个?
答案 0 :(得分:0)
您为每个用户获取了多个值,因为您在GROUP BY
子句中列出了多个字段:
GROUP BY Roster.UserID,
EventLog.Type,
IIf([EventLog]![LogType] Like "Acc*" And
[EventLog]![Action] Like "Wri*",[EventLog]![Date],Date()-183)
我不确定你为什么要分组,因为你没有执行任何聚合功能。 SELECT DISTINCT
会有效吗?
答案 1 :(得分:0)
感谢您的反馈意见。基于Beth回复并清理我的表格和查询以发送dBase的副本,问题似乎通过一小部分代码自行解决。
SELECT Roster.UserID,
EventLog.Type,
Max(IIf(EventLog!LogType Like "Acc*" And EventLog!Action Like "Wri*",EventLog!Date,Date()-183)) AS [Review Date]
FROM EventLog
INNER JOIN Roster
ON EventLog.UserID = Roster.UserID
GROUP BY Roster.UserID,
EventLog.Type
HAVING (((EventLog.Type) Like "Att*"));
Beth对多场的清理工作得很好!!!