剛寫錯..沒把只有sec的算進去
正確的 SQL server版
<pre class="c" name="code">
declare @t table
(sn int primary key,name varchar(10),totalTime varchar(80))
insert into @t values (1,'Liu','8min20sec'),(2,'Chiu','32min8sec'),(3,'Wang','21sec')
select sum(datepart(mi,'1900/01/01 00:' + replace(
case when charindex('min',totalTime)>0 then REPLACE(totalTime,'min',':') else '0:'+totalTime end,'sec',''))*60+
datepart(s,'1900/01/01 00:' + replace(
case when charindex('min',totalTime)>0 then REPLACE(totalTime,'min',':') else '0:'+totalTime end,'sec','')))
from @t
忘了轉成 時:分:秒
下面的select 改成
<pre class="c" name="code">
select convert(varchar,dateadd(s,sum(datepart(mi,'1900/01/01 00:' + replace(
case when charindex('min',totalTime)>0 then REPLACE(totalTime,'min',':') else '0:'+totalTime end,'sec',''))*60+
datepart(s,'1900/01/01 00:' + replace(
case when charindex('min',totalTime)>0 then REPLACE(totalTime,'min',':') else '0:'+totalTime end,'sec',''))),0),108)
from @t
請教大家
如果要在EXCEL直接透過函數算出總時間,要如何做呢?
我試著使用自訂格式的方式,指定為hh:mm:ss,但在時間的加總結果卻是顯示00:00:00, 謝謝