构建包含详细信息的交叉表查询

To build a cross tab query with details

我需要在 ms access 中构建交叉表查询,但我需要显示详细信息而不是汇总信息。

我有一个table喜欢:

Date Teamname Teammemebername

交叉表应该有:

如何做到这一点?

ID  ScheduleDate    TeamCode    TeamMemberCode
5585    3/4/2022    NT      NW
5586    3/4/2022    USHRL   RN
5587    3/4/2022    USHRT   KN
5588    3/4/2022    USHRT   KI
5589    3/4/2022    USHRT   RF
5590    3/11/2022   NT      MF
5591    3/11/2022   USHRL   QD
5592    3/11/2022   USHRT   NW
5593    3/11/2022   USHRT   KN
5594    3/11/2022   USHRT   KI

第一个答案不正确: 将 First(tblTeamdata.Teammemebername) 转换为 FirstMembername SELECT tblTeamdata.DAT 来自 tblTeamdata 分组依据 tblTeamdata.DAT 枢轴 tblTeamdata.Teamname;

由于交叉表中的每个单元格都可以有多个成员代码,因此您必须使用一个函数来 return 这些名称的列表。该函数应将日期和团队代码作为参数。

Function names(dat As Variant, team As Variant)
    Dim res$, sql$
    Dim rs As DAO.Recordset
    If IsNull(dat) Or IsNull(team) Then
        names = Null
    Else
        sql = "SELECT * FROM Teamdata"
        sql = sql & " Where ScheduleDate =#" & dat & "#"
        sql = sql & " AND TeamCode=""" & team & """"
        sql = sql & " Order by TeamMemberCode;"
        Set rs = CurrentDb.OpenRecordset(sql)
        Do Until rs.EOF
            If res <> "" Then res = res & ","
            res = res & rs!TeamMemberCode
            rs.MoveNext
        Loop
        rs.Close
        names = res
    End If
End Function

TRANSFORM names([ScheduleDate],[Teamcode]) 作为结果 SELECT TeamData.ScheduleDate 来自团队数据 分组依据 TeamData.ScheduleDate 枢轴 TeamData.TeamCode;

以上数据集的查询结果将是:

ScheduleDate  NT    USHRL   USHRT
2022-03-04    NW    RN      KI,KN,RF
2022-03-11    MF    QD      KI,KN,NW