Sqlite和时间
我有一个包含事件持续时间的列的表。 格式为“h:mm:ss” 我找到了strftime函数-但根据手册,它需要格式为“hh:mm:ss”Sqlite和时间,sqlite,Sqlite,我有一个包含事件持续时间的列的表。 格式为“h:mm:ss” 我找到了strftime函数-但根据手册,它需要格式为“hh:mm:ss” 有人能告诉我如何在不重新创建sql表的情况下总结持续时间吗?这是您想要的吗 with t as ( select '4:02:01' as v union all select '9:30:12' union all select '2:14:00' ), diff as ( select sum(strftime('%s', '0'||
有人能告诉我如何在不重新创建sql表的情况下总结持续时间吗?这是您想要的吗
with t as (
select '4:02:01' as v
union all
select '9:30:12'
union all
select '2:14:00'
),
diff as (
select sum(strftime('%s', '0'||v) - strftime('%s', '00:00:00')) as v
from t
)
select (v/3600) || ' hours, ' || (v%3600/60) ||' minutes, '
|| (v%60) || ' seconds.'
from diff
您可以使用time()
和strftime()
:
结果时间总和的格式为
hh:mm:ss
您能发布样本数据和预期结果吗?
select
time(sum(
strftime('%s', case length(timecolumn) when 7 then '0' else '' end || timecolumn)
- strftime('%s','00:00:00')),
'unixepoch') totaltime
from tablename