关于多个月份日期的快速 SQL 问题

发布于 2024-10-20 05:42:14 字数 1040 浏览 10 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里泪两行 2024-10-27 05:42:14

您希望按年份和月份而不是 tblSupportCalls.Date 进行分组。

...
GROUP BY tblSupportCalls.System, Year([Date]), Month([Date]);

You'd want to group by your Year and Month instead of tblSupportCalls.Date.

...
GROUP BY tblSupportCalls.System, Year([Date]), Month([Date]);
阳光的暖冬 2024-10-27 05:42:14

不过,您仍然按日期对结果进行分组(而不是按月份)。我认为您想要的是这样的:

GROUP BY tblSupportCalls.System, Year ([tblSupportCalls.Date]), [Month([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:

GROUP BY tblSupportCalls.System, Year ([tblSupportCalls.Date]), [Month([tblSupportCalls.Date]);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文