1661.每台机器的进程
表: Activity
| Column Name | Type |
|---|---|
| machine_id | int |
方法1:窗口函数
select machine_id,round(avg(sumtime),3)as processing_time
from
(select *,end_timestamp-timestamp as sumtime
from
(select *,
lead(timestamp,1) over (partition by machine_id,process_id
order by activity_type asc) as end_timestamp
from activity) as a
where end_timestamp is not null) as b
group by machine_id;
方法2:表连接