在给定两个小时的MySQL的情况下,选择在各行中拆分一行
你好社区你好吗? 假设我在表
ID | 启动 | 端 | Intertal1 | Interval2 |
---|---|---|---|---|
1 | 12:00:00 | 16:00:00 | 55 | 5 |
中有此行并添加Interval1+Interval2直到字段结束。在此示例(12:00:00 +(55 + 5))中,它将返回
ID | 启动 | 端 | Internet1 | Interval2 |
---|---|---|---|---|
1 | 12:00:00 | 16:00:00 | 55 | 5 |
1 | 13:00:00 16:00 | 16:00:00 | 55 5 | 5 |
1 | 14:00:00 | 16:00:00 | 55 | 5 |
1 | 15:00:00 | 16:00:00 | 55 | 5 |
1 | 16:00:00 | 16:00:00 | 55 | 5 |
我与MySQL相当新,而Ive挣扎了几个小时。 谢谢大家!
Hello community how are u doing.
Lets say i have this row in a table
id | start | end | interval1 | interval2 |
---|---|---|---|---|
1 | 12:00:00 | 16:00:00 | 55 | 5 |
So id like to create a view where i give the id as condition and it returns me rows from the field start and adding interval1+interval2 until the field end. In this example (12:00:00 + (55 + 5)) it would return
id | start | end | interval1 | interval2 |
---|---|---|---|---|
1 | 12:00:00 | 16:00:00 | 55 | 5 |
1 | 13:00:00 | 16:00:00 | 55 | 5 |
1 | 14:00:00 | 16:00:00 | 55 | 5 |
1 | 15:00:00 | 16:00:00 | 55 | 5 |
1 | 16:00:00 | 16:00:00 | 55 | 5 |
Im pretty new with mysql and ive been struggling for hours.
Thank u all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于MySQL V8,可以使用递归CTE -DB
小提琴
For mysql v8, recursive CTE can be used -
DB fiddle here.
假设在每个行Interval1和Interval2中可能具有不同的值,并且我们希望显示一个比一个ID的结果,甚至创建视图,仅
横向>横向
可以分别为每一行完成工作。它在8.0.14中添加。之后
Assuming, that in each row interval1 and interval2 may have different values, and we want to display results for more then one ID, or even create a view, only
LATERAL
can do the job for each row separately. It was added in 8.0.14.and after that
DB Fiddle