获取当天的事件总数

发布于 2025-01-04 21:19:11 字数 1468 浏览 0 评论 0原文

如何获取当天登记的带有 UNIX 时间戳的当前事件的数量,例如,2012 年 2 月 17 日有 2 个事件,2012 年 2 月 19 日有 1 个事件。它应该返回如下行:

Array 
(
    [0] => stdClass Object
        (
           [event_id] => 4
           [total_events] => 2
        )

    [1] => stdClass Object
        (
           [event_id] => 18
           [total_events] => 2
        )

    [2] => stdClass Object
        (
           [event_id] => 19
           [total_events] => 1
        )
)

前两个项目安排在同一天(2 月 17 日),最后一个项目安排在 2 月 19 日,同一天没有安排其他活动。

我尝试了这个方法,但它返回了这个:

Array
(
    [0] => stdClass Object
        (
            [event_id] => 1
            [total_events] => 1
        )

    [1] => stdClass Object
        (
            [event_id] => 2
            [total_events] => 1
        )

    [2] => stdClass Object
        (
            [event_id] => 3
            [total_events] => 1
        )

)

这是我到目前为止所做的以下 SQL,但没有好的结果:

SELECT events.event_id,
       SUM(IF(DATE_FORMAT(FROM_UNIXTIME(events.event_starts), '%y %m %d') = DATE_FORMAT(FROM_UNIXTIME(events.event_ends), '%y %m %d'), 1, 0)) AS total_events

FROM
(
    scheduled_events events
)
WHERE ( events.event_starts >= 1328486400 AND events.event_ends <= 1329695940 )
GROUP BY events.event_id

两个 UNIX 时间戳的范围是从 2 月 13 日星期一 12:00AM 到 2 月 19 日星期日 11:59PM,如下所示接下来一周的计划。

当后续事件的当天有事件时,如何检索返回一周中每一天的事件数的事件数。

How can you get the number of current events that are enlisted on a current day with a UNIX timestamp, for example, there are 2 events on 17th February 2012 and 1 event on 19th February 2012. It should return rows like this:

Array 
(
    [0] => stdClass Object
        (
           [event_id] => 4
           [total_events] => 2
        )

    [1] => stdClass Object
        (
           [event_id] => 18
           [total_events] => 2
        )

    [2] => stdClass Object
        (
           [event_id] => 19
           [total_events] => 1
        )
)

The first two items are scheduled on the same day of each other (17th Feb) and the last item is on the 19th of Feb with no other events scheduled the same day.

I tried this method, but it returns this:

Array
(
    [0] => stdClass Object
        (
            [event_id] => 1
            [total_events] => 1
        )

    [1] => stdClass Object
        (
            [event_id] => 2
            [total_events] => 1
        )

    [2] => stdClass Object
        (
            [event_id] => 3
            [total_events] => 1
        )

)

This is the following SQL I've done so far, without a good result:

SELECT events.event_id,
       SUM(IF(DATE_FORMAT(FROM_UNIXTIME(events.event_starts), '%y %m %d') = DATE_FORMAT(FROM_UNIXTIME(events.event_ends), '%y %m %d'), 1, 0)) AS total_events

FROM
(
    scheduled_events events
)
WHERE ( events.event_starts >= 1328486400 AND events.event_ends <= 1329695940 )
GROUP BY events.event_id

The two UNIX timestamps are ranging from Monday 13th Feb 12:00AM to Sunday 19th Feb 11:59PM as in of the following week scheme.

How do I retrieve the number of events that returns the number of events on each day of the week when there is an event on that day of a following event.

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

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

发布评论

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

评论(1

烟花肆意 2025-01-11 21:19:11

这应该可以帮助您开始。它应该返回两个时间戳内的每个 event_id 以及同一天开始的所有其他 event_id 的 COUNT

SELECT e1.event_id,
       COUNT(DISTINCT e2.event_id)
FROM   scheduled_events AS e1
   INNER JOIN scheduled_events AS e2
       ON  e1.event_id!=e2.event_id 
           AND DATE(FROM_UNIXTIME(e1.event_starts))=DATE(FROM_UNIXTIME(e2.event_starts))
WHERE ( e1.event_starts >= 1328486400 AND e1.event_ends <= 1329695940 )
GROUP BY e1.event_id

This should get you started. It should return each event_id within the two timestamps and a COUNT of all other event_ids that start on the same day

SELECT e1.event_id,
       COUNT(DISTINCT e2.event_id)
FROM   scheduled_events AS e1
   INNER JOIN scheduled_events AS e2
       ON  e1.event_id!=e2.event_id 
           AND DATE(FROM_UNIXTIME(e1.event_starts))=DATE(FROM_UNIXTIME(e2.event_starts))
WHERE ( e1.event_starts >= 1328486400 AND e1.event_ends <= 1329695940 )
GROUP BY e1.event_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文