E_status 状态有很多种 如: STOPS, RUN,DOWN,SETUP,DEA
e_id 机台编号 A1,A2
l_id 线别 A ,B ,一条线可以有多个机台
start_time 开始时间,每次切换状态的时间 要得到每次距离RUN最近的一笔的时间,如果没有距离最近的时间,则默认今天的最大时间
l_id e_id E_status start_time
A A1 DOWN 2000-11-11 10:00:00
A A1 RUN 2000-11-11 11:00:00
A A1 DOWN 2000-11-11 12:00:00
A A1 SETUP 2000-11-11 12:30:00
A A1 DOWN 2000-11-11 13:00:00
A A1 RUN 2000-11-11 15:00:00
A A1 DOWN 2000-11-11 16:00:00
A A2 DOWN 2000-11-11 10:00:00
A A2 RUN 2000-11-11 11:00:00
A A2 RUN 2000-11-11 12:00:00
A A2 RUN 2000-11-11 13:00:00
A A2 DOWN 2000-11-11 14:00:00
A A2 RUN 2000-11-11 18:00:00
得到如下结果。
l_id e_id E_status start_time nest_time
A A1 RUN 2000-11-11 11:00:00 2000-11-11 12:00:00
A A1 RUN 2000-11-11 15:00:00 2000-11-11 16:00:00
A A2 RUN 2000-11-11 11:00:00 2000-11-11 12:00:00
A A2 RUN 2000-11-11 12:00:00 2000-11-11 13:00:00
A A2 RUN 2000-11-11 13:00:00 2000-11-11 14:00:00
A A2 RUN 2000-11-11 18:00:00 2000-11-11 23:59:95
e_id 机台编号 A1,A2
l_id 线别 A ,B ,一条线可以有多个机台
start_time 开始时间,每次切换状态的时间 要得到每次距离RUN最近的一笔的时间,如果没有距离最近的时间,则默认今天的最大时间
l_id e_id E_status start_time
A A1 DOWN 2000-11-11 10:00:00
A A1 RUN 2000-11-11 11:00:00
A A1 DOWN 2000-11-11 12:00:00
A A1 SETUP 2000-11-11 12:30:00
A A1 DOWN 2000-11-11 13:00:00
A A1 RUN 2000-11-11 15:00:00
A A1 DOWN 2000-11-11 16:00:00
A A2 DOWN 2000-11-11 10:00:00
A A2 RUN 2000-11-11 11:00:00
A A2 RUN 2000-11-11 12:00:00
A A2 RUN 2000-11-11 13:00:00
A A2 DOWN 2000-11-11 14:00:00
A A2 RUN 2000-11-11 18:00:00
得到如下结果。
l_id e_id E_status start_time nest_time
A A1 RUN 2000-11-11 11:00:00 2000-11-11 12:00:00
A A1 RUN 2000-11-11 15:00:00 2000-11-11 16:00:00
A A2 RUN 2000-11-11 11:00:00 2000-11-11 12:00:00
A A2 RUN 2000-11-11 12:00:00 2000-11-11 13:00:00
A A2 RUN 2000-11-11 13:00:00 2000-11-11 14:00:00
A A2 RUN 2000-11-11 18:00:00 2000-11-11 23:59:95
解决方案 »
- pl/sql developer 导出数据的三种方式有和区别?
- 外连接的问题,请教
- 这样的 语句怎么写啊
- (高手问题)distinct和order by 问题求解
- Oracle数据库统计查询问题?
- SQL 执行效率问题
- 求教,SQL存储过程移植到——oracle存储过程。
- 请问SGA 中SQL共享池中的运行数据库所需的临时数据与数据缓冲区中的数据库对象数据有什么区别
- ORA-12560: TNS:protocol adapter error
- 奇怪!sql/plus可以登陆上,而在有的机器软件里通过ado连接不上,有很少机器!!
- 自定义TABLE类型数据,如何赋值给一个游标从存过中返回
- 初学Oracle,问一个时间段排序的问题。根据三个月内,点击率CTR从高到低排序整个表。
关注,up
select tt.*,nvl(lead(start_time)over(partition by l_id,e_id order by start_time),sysdate)next_time
from tt)
where e_status='RUN'
select a.*,nvl(b.start_time,sysdate)next_time
from tt a,tt b
where a.e_status='RUN'
and a.l_id=b.l_id(+)
and a.e_id=b.e_id(+)
and a.start_Time<b.start_time(+)
and not exists(select 1 from tt where l_id=b.l_id and e_id=b.e_id and start_time<b.start_time and start_time>a.start_time)
order by 1,2,5效率应该没有上面的高