示例查询结果
Employee_Last Employee_First RoleName CourseName CourseStart CourseEnd Attended
Ables Christopher ServiceMGR OTC Training 12/1/11 12/1/11 Yes
Ables Christopher ServiceMGR No
Ables Christopher ServiceMGR OTC Part 1 12/5/11 12/5/11 Yes
Ables Christopher AssetShipper No
Ables Christopher AssetShipper No
Ables Christopher AssetShipper No
Ables Christopher AssetShipper No
这些是我从查询中得到的结果,有许多查询从表中提取以获取此数据。数据库已标准化 我想要创建的报告是关注Attended的。
If Yes
Show all of the line item from the query
Else If
If RoleName is listed previously for a specific employee and attended =
yes on that line item(ie: Ables | Christopher | ServiceMGR | No -- should not be seen)
Don't Show
Else If RoleName is listed previously for a specific employee and Attended = No
Only Show the item once(ie: Should only see Ables | Christopher | AssetShipper | No)
End If
End IF
因此可能需要另一个Query来过滤此查询。我正在从样本数据中寻找的报告应如下所示:
Employee_Last Employee_First RoleName CourseName CourseStart CourseEnd Attended
Ables Christopher ServiceMGR OTC Training 12/1/11 12/1/11 Yes
Ables Christopher ServiceMGR OTC Part 1 12/5/11 12/5/11 Yes
Ables Christopher AssetShipper No
希望你能看到我在说什么。我已经做过一些关于如何隐藏和显示记录的研究,但我对Access不够熟悉。所以基本上我需要过滤Attended = No's对最终用户有意义。
答案 0 :(得分:2)
也许就是这些问题:
SELECT employee_last,
employee_first,
rolename,
coursename,
coursestart,
courseend,
attended
FROM attend
WHERE attended = "Yes"
UNION
SELECT DISTINCT b.employee_last,
b.employee_first,
b.rolename,
NULL AS coursename,
NULL AS coursestart,
NULL AS courseend,
b.attended
FROM (SELECT employee_last,
employee_first,
rolename
FROM attend
WHERE attended = "Yes") AS a
RIGHT JOIN (SELECT employee_last,
employee_first,
rolename,
attended
FROM attend
WHERE attended = "No") AS b
ON ( a.rolename = b.rolename )
AND ( a.employee_first = b.employee_first )
AND ( a.employee_last = b.employee_last )
WHERE (( ( a.employee_last ) IS NULL ))