0

我在 Microsoft Access 中有一个联系人数据库,所有数据都在一个表中。我正在尝试创建一个按“状态”对用户进行分组的报告,但在尝试确定如何执行此操作时遇到了麻烦。

每个联系人都有两个字段,状态 1 和状态 2。状态 1 可以为空,A 或 B,状态 2 可以为真或假。

报告应将它们分组如下:

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 报告中,我无法弄清楚该怎么做。

谢谢!

4

1 回答 1

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
于 2012-11-05T12:54:49.467 回答