我有 2 tbls 如下。
请求表
id | request | created
1 | asdf | 2013-07-04 14:39:03
2 | qwer | 2013-07-10 12:06:37
历史表
id | request_id | status | date
1 | 1 | Pending | 2013-07-04 14:39:03
2 | 1 | Reviewing | 2013-07-05 01:10:14
3 | 1 | Implementing | 2013-07-06 11:25:54
4 | 1 | Completed | 2013-07-07 12:36:32
5 | 2 | Pending | 2013-07-10 15:05:56
6 | 2 | Reviewing | 2013-07-11 03:08:04
7 | 2 | Implementing | 2013-07-13 11:45:48
8 | 2 | Completed | 2013-07-17 14:28:15
我想在 2 tbls 以上显示如下
Request | Reviewing Time | Implementing Time
asdf | 0 | 0
qwer | 1 | 2
以 request_id = 1 为例的理论是
审查到实施 = (2013-08-06) - (2013-08-05) = 1 天
待审核 = (2013-08-05) - (2013-08-04) = 1 天
审核时间=(审核到实施)-(待审核)= 0天
审查到实施 = (2013-08-06) - (2013-08-05) = 1 天
实施至完成 = (2013-08-07) - (2013-08-06) = 1 天
实施时间=(实施到完成)-(审查到实施)= 0