with data as --Data example. Use your table instead
(select '12:10:30' start_time,'01:10:00' end_time, '02:10:00' duration)
select from_unixtime(cast((unix_timestamp(start_time,'HH:mm:ss')+ unix_timestamp(end_time,'HH:mm:ss')+unix_timestamp(duration,'HH:mm:ss'))/3 as bigint),'HH:mm:ss') from data;
with data as --Data example. Use your table instead
(select stack(2,'12:10:30','01:10:00') as timeStr)
select from_unixtime(cast(avg(unix_timestamp(timeStr,'HH:mm:ss'))as bigint),'HH:mm:ss') from data;
1条答案
按热度按时间zsohkypk1#
转换为unix\u timestamp,sum,除以3,转换为bigint并转换回hh:mm:ss:
结果:
请参见此处的测试:http://demo.gethue.com/hue/editor?editor=285484&type=hive
对于单列:
转换为unix timestamp,以秒为单位计算平均值,转换为bigint(平均值是double,会有部分秒精度损失),最后将其转换回字符串时间格式:
结果:
请参见此处的测试:http://demo.gethue.com/hue/editor?editor=285464&type=hive