【发布时间】:2021-04-05 02:24:35
【问题描述】:
我想要实现的目标。
我有一个名为 calls 的表,其中包含 started_at:datetime、end_at:datetime、handler:string 列。
| id | started_at | end_at | handler | agent_id |
|---|---|---|---|---|
| 1 | 2021-04-05T02:00:00Z | 2021-04-05T03:30:00Z | fg456fghj | 1 |
| 2 | 2021-04-05T03:40:00Z | 2021-04-05T04:30:00Z | cvbnmfghh | 1 |
| 3 | 2021-04-05T04:40:00Z | 2021-04-05T05:00:00Z | wertyuuuu | 1 |
| 4 | 2021-04-06T01:40:00Z | 2021-04-05T02:00:00Z | 34sdfertt | 1 |
我想要一个像这样的新表
| id | hour | minutes_logged |
|---|---|---|
| 1 | 02 of 2021-04-05 | 60 |
| 2 | 03 of 2021-04-05 | 50 |
| 3 | 04 of 2021-04-05 | 50 |
| 4 | 01 of 2021-04-06 | 20 |
注意:
minutes_logged 不能超过 60 分钟,因为一个小时只有 60 分钟。
我的发现
对于hour 专栏,我可以写的是
concat(extract(hour from calls.started_at), ' of ', calls.started_at::date) as hour
但我无法正确地为minutes_logged 写信。
主要问题
我无法编写查询来将时间范围分成多行。请帮忙。我感谢你的努力。提前致谢。
【问题讨论】:
标签: postgresql