Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite和时间_Sqlite - Fatal编程技术网

Sqlite和时间

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'||

我有一个包含事件持续时间的列的表。 格式为“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'||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