使用 SQL 查询返回每周创建的票证数量

发布于 2024-10-21 01:23:56 字数 166 浏览 1 评论 0原文

我有一个票证表 common_ticket,其中有一列名为creation_date,用于保存创建日期。

我想计算过去几个月每周创建的票证数量。我在编写 SQL 查询来返回此类信息时遇到问题。如何返回并不重要,只要每个单独的周都有一个不同的数字即可。

有人对如何做到这一点有任何想法吗?

I have a table of tickets, common_ticket, with a column called creation_date, which holds the date of creation.

I want to count how many tickets were created each week for the past few months. I am having trouble writing a SQL query to return such information. How it is returned is not really important as long as there is a distinct number for each separate week.

Does anyone have any ideas on how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

又爬满兰若 2024-10-28 01:23:56

像这样的东西:

SELECT extract(week from creation_date), 
       extract(year from creation_date),
       count(*)
FROM tickets
GROUP BY extract(week from creation_date), 
         extract(year from creation_date)

Something like:

SELECT extract(week from creation_date), 
       extract(year from creation_date),
       count(*)
FROM tickets
GROUP BY extract(week from creation_date), 
         extract(year from creation_date)
我很坚强 2024-10-28 01:23:56

这应该可以做到:

SELECT [t1].[value] AS [Year], [t1].[value2] AS [Week], COUNT(*) AS [Count]
FROM (
    SELECT DATEPART(Year, [t0].[creation_date]) AS [value],
        DATEPART(Week, [t0].[creation_date]) AS [value2]
    FROM [common_ticket] AS [t0]
) AS [t1]
GROUP BY [t1].[value], [t1].[value2];

this should do it:

SELECT [t1].[value] AS [Year], [t1].[value2] AS [Week], COUNT(*) AS [Count]
FROM (
    SELECT DATEPART(Year, [t0].[creation_date]) AS [value],
        DATEPART(Week, [t0].[creation_date]) AS [value2]
    FROM [common_ticket] AS [t0]
) AS [t1]
GROUP BY [t1].[value], [t1].[value2];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文