我有2 tbls如下。如何在MySQL中使用2個表編寫計算查詢?
請求TBL
id | request | created
1 | asdf | 2013-07-04 14:39:03
2 | qwer | 2013-07-10 12:06:37
歷史TBL
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年8月6日) - (2013年8月5日)=1天(2013-08-07) - (2013-08-06)= 1天
實施時間 =(落實compeleted) - (審查對 實施)= 0