关于多个月份日期的快速 SQL 问题
SELECT DISTINCT MonthName(Month([Date])) AS [Month], tblSupportCalls.System, Count(tblSupportCalls.System) AS [Total for System], Year([Date]) AS [Year]
FROM tblSupportCalls
WHERE (((tblSupportCalls.Date) Between Now() And Now()-7) AND ((tblSupportCalls.System) In ('Career Campus','E-PEEP')) AND ((tblSupportCalls.StartTime) Is Not Null) AND ((Hour([StartTime]))>=7))
GROUP BY tblSupportCalls.System, tblSupportCalls.Date;
每当我输入它时,它都会给我多个月份,例如:
July
July
July
我只想说七月一次,我不明白为什么每个字段都会在不同的日子重复。我只想说:
月|系统|整体系统| 年份
我所看到的
> MONTH | System | Total Systems | Year
> July CC 2 2010
> July CC 7 2010
> July CC 9 2010
> July EE 1 2010
> July EE 2 2010
需要是:
MONTH | System | Total Systems | Year
July CC 18 2010
July EE 03 2010
SELECT DISTINCT MonthName(Month([Date])) AS [Month], tblSupportCalls.System, Count(tblSupportCalls.System) AS [Total for System], Year([Date]) AS [Year]
FROM tblSupportCalls
WHERE (((tblSupportCalls.Date) Between Now() And Now()-7) AND ((tblSupportCalls.System) In ('Career Campus','E-PEEP')) AND ((tblSupportCalls.StartTime) Is Not Null) AND ((Hour([StartTime]))>=7))
GROUP BY tblSupportCalls.System, tblSupportCalls.Date;
Whenever I input that it gives me multiple months like:
July
July
July
I want it just to say July just 1 time and I cant figure out why ever field is repeating itself for different days. I just want it to say:
MONTH | System | Total Systems | Year
what I am looking at is
> MONTH | System | Total Systems | Year
> July CC 2 2010
> July CC 7 2010
> July CC 9 2010
> July EE 1 2010
> July EE 2 2010
Needs to be:
MONTH | System | Total Systems | Year
July CC 18 2010
July EE 03 2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望按年份和月份而不是
tblSupportCalls.Date
进行分组。You'd want to group by your Year and Month instead of
tblSupportCalls.Date
.不过,您仍然按日期对结果进行分组(而不是按月份)。我认为您想要的是这样的:
我想您仍然想按年份分组,以便 2010 年 7 月与 2011 年 7 月显示在不同的行中。
You're still grouping the results by date, though (not by month). I think what you want is something like this:
I'm thinking you still want to group by Year as well, so that July 2010 shows up in a different row from July 2011.