数据库表table结构如下 start_time duration
----------------------------------
2006-4-22 21:40:00 2007-3-12 00:10:00
2006-4-22 22:00:00 2007-3-12 00:30:00
----------------------------------
说明:start_time 和duration的类型都是date型
现在要生成一个视图,视图的一个列名为end_time
end_time是start_time的全部数据加上duration的小时分钟和秒的数据,
和duration中的年月日无关
例如:
2006-4-22 21:40:00+2007-3-12 00:10:00=2006-4-22 21:50:00
2006-4-22 22:00:00+2007-3-12 00:30:00=2006-4-22 22:30:00
2006-4-22 22:00:00+2007-3-12 00:20:00=2006-4-22 22:20:00
2006-4-22 22:00:00+2007-3-12 01:30:00=2006-4-22 23:30:00
2006-4-22 22:00:00+2007-3-12 02:30:00=2006-4-23 00:30:00这个视图的SQL怎么写?尤其是跨天的计算
----------------------------------
2006-4-22 21:40:00 2007-3-12 00:10:00
2006-4-22 22:00:00 2007-3-12 00:30:00
----------------------------------
说明:start_time 和duration的类型都是date型
现在要生成一个视图,视图的一个列名为end_time
end_time是start_time的全部数据加上duration的小时分钟和秒的数据,
和duration中的年月日无关
例如:
2006-4-22 21:40:00+2007-3-12 00:10:00=2006-4-22 21:50:00
2006-4-22 22:00:00+2007-3-12 00:30:00=2006-4-22 22:30:00
2006-4-22 22:00:00+2007-3-12 00:20:00=2006-4-22 22:20:00
2006-4-22 22:00:00+2007-3-12 01:30:00=2006-4-22 23:30:00
2006-4-22 22:00:00+2007-3-12 02:30:00=2006-4-23 00:30:00这个视图的SQL怎么写?尤其是跨天的计算
和
select start_time,start_time+(duration-trunc(duration,'dd')) end_time from table
都可行,谢谢大家,给分结贴