需要来自 MySql 数据库的日期块数组
好的,我有一个包含 StartDate 和 EndDate 的行的数据库表。我需要做的是从中返回消耗的时间块。
因此,举例来说,如果我有 3 行,如下所示:
RowID StartDate EndDate
1 2011-01-01 2011-02-01
2 2011-01-30 2011-02-20
3 2011-03-01 2011-04-01
那么所用时间块将如下所示:
2011-01-01至2011-02-20和2011-03-01至2011-04-01
有没有一种简单的方法从 MySql 数据库中提取它?欢迎任何建议!
Ok, I have a database table of rows with a StartDate and an EndDate. What I need to do is return blocks of consumed time from that.
So, for example, if I have 3 rows as follows:
RowID StartDate EndDate
1 2011-01-01 2011-02-01
2 2011-01-30 2011-02-20
3 2011-03-01 2011-04-01
then the blocks of used time would be as follows:
2011-01-01 to 2011-02-20 and 2011-03-01 to 2011-04-01
Is there an easy method of extracting that from a MySql database? Any suggestions welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请看下图,它表示一些重叠的时间段。
用
X
标记的任何连续时间段的开始或结束不属于任何其他时间段。如果我们确定这些时间,我们就能取得一些进展。该查询标识边界。
对您的数据进行此查询的结果是
您所查询的日期范围位于上面显示的连续下限和上限之间。通过一些后期处理,可以很容易地找到这些。
Look at the diagram below which represents some overlapping time periods
The beginning or end of any contiguous time period, marked with an
X
doesn't fall inside any other time period. If we identify these times we can make some progress.This query identifies the boundaries.
The result of this query on your data is
The date ranges you are after are between consecutive lower and upper bounds shown abouve. With a bit of post processing, these can easily be found.
您是否尝试过 mysql group concat
http:// /dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
它将返回一个逗号分隔的字符串,但您仍然需要将其初始化为数组你的 应用。
Have you tried mysql group concat
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
It would return a comma separated string, but you would still have to intialize that as an array in your application.