通过匹配日期访问总和。排序不起作用

时间:2016-04-07 09:25:26

标签: sorting date ms-access sum match

好的,所以我为老师提供了以下标题的时间表 Date=>StartTime=>EndTime=>Type=>Teacher=>Discipline=>Hours

它考虑了与学生一起度过的小时数 对于月底的报告

重点是总结所有数学

    Date=>         =>         =>Type=>Teacher=>Discipline=>

我使用Sum

这样做了
    SELECT DISTINCTROW Format$([Sched].[Date],'Long Date') AS Date, [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type], Sum([Sched].[Hours]) AS [Sum Of Hours]
    FROM [Sched]
    GROUP BY Format$([Sched].[Date],'Long Date'), [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type];

问题是,如果您尝试按日期对此进行排序,则看起来日期

是错误的

april 1=>april 13=>15=>16=>april 2(???)=>20=>23=>27=>6(???)=>8=>9

如何测试此错误?

1 个答案:

答案 0 :(得分:0)

You can't order date strings with this format.

Order by date value:

SELECT DISTINCTROW 
    Format$([Sched].[Date],'Long Date') AS Date, [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type], Sum([Sched].[Hours]) AS [Sum Of Hours]
FROM 
    [Sched]
GROUP BY 
    Format$([Sched].[Date],'Long Date'), [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type]
ORDER BY 
    [Sched].[Date], [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type];

or use a sortable date format:

SELECT DISTINCTROW 
    Format$([Sched].[Date],'yyyy-mm-dd') AS Date, [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type], Sum([Sched].[Hours]) AS [Sum Of Hours]
FROM 
    [Sched]
GROUP BY 
    Format$([Sched].[Date],'yyyy-mm-dd'), [Sched].[Tacher], [Sched].[Discipline], [Sched].[Type];