使用此查詢
SQL> WITH table_(Email, Time) as (
2 select '[email protected]', '00:10:40' from dual union all
3 select '[email protected]', '00:40:10' from dual union all
4 select '[email protected]', '01:10:20' from dual union all
5 select '[email protected]', '00:43:40' from dual union all
6 select '[email protected]', '00:42:40' from dual union all
7 select '[email protected]', '00:30:40' from dual union all
8 select '[email protected]', '00:54:10' from dual union all
9 select '[email protected]', '00:47:40' from dual union all
10 select '[email protected]', '00:50:40' from dual union all
11 select '[email protected]', '01:05:40' from dual union all
12 select '[email protected]', '00:45:40' from dual union all
13 select '[email protected]', '00:51:40' from dual union all
14 select '[email protected]', '00:36:40' from dual)
15 ---------------------
16 -- End if sample data
17 ---------------------
18 SELECT email, numtodsinterval(sum(SUBSTR(TIME, 1, 2)*3600 + SUBSTR(TIME, 4, 2)*60 + SUBSTR(TIME, 7, 2)), 'SECOND') total_duration
19 FROM table_
20 GROUP BY email;
輸出:
EMAIL TOTAL_DURATION
---------------- --------------------------------------------------------------------------------
[email protected] +000000000 02:12:30.000000000
[email protected] +000000000 04:10:20.000000000
[email protected] +000000000 03:27:30.000000000
所以,你的查詢是
SELECT email, numtodsinterval(sum(SUBSTR(TIME, 1, 2)*3600 + SUBSTR(TIME, 4, 2)*60 + SUBSTR(TIME, 7, 2)), 'SECOND') total_duration
FROM table_
GROUP BY email;
來源
2017-03-03 14:10:15
San
我猜想這就是持續時間不是時間,正確嗎? – tbone
@tbone是持續時間 –
總結持續時間(無論如何11g)並不簡單,請參閱[本文](http://stackoverflow.com/questions/16812762/convert-varchar2-into-number/16816494#16816494) – tbone