获取当天的事件总数
如何获取当天登记的带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以帮助您开始。它应该返回两个时间戳内的每个 event_id 以及同一天开始的所有其他 event_id 的 COUNT
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