我在Microsoft Access中有一个联系人数据库,其中包含一个表中的所有数据。我正在尝试创建一个报告,按“状态”对用户进行分组,但我无法确定如何执行此操作。
每个联系人都有两个字段,状态1和状态2.状态1可以为空,A或B,状态2可以为true或false。
报告应该将它们分组:
Status 1 Null
Contact name and details (repeated for every contact with this status)
Status 1 A
Contact name and details (repeated for every contact with this status)
Status 1 B
Contact name and details (repeated for every contact with this status)
Status 2 True
Contact name and details (repeated for every contact with this status)
这些状态会有一些重叠,因为有些记录会匹配多个状态,但这很好。在此页面上显示重复项是完全可以接受的。
如果这是一个Web应用程序,我只需编写4个查询并在结果记录集中循环,在每个适当的标题下显示结果。但是在Access报告中,我无法弄清楚要做什么。
谢谢!
答案 0 :(得分:1)
您可以考虑将报告基于UNION查询:
SELECT 1 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable
WHERE Status1 Is Null
UNION ALL
SELECT 2 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable
WHERE Status1 = "A"
UNION ALL
SELECT 3 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable
WHERE Status1 = "B"
UNION ALL
SELECT 4 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable
WHERE Status2 = True