leetcode 1661. 每台机器的进程平均运行时间

173 阅读1分钟

1661. 每台机器的进程平均运行时间 - 力扣(LeetCode)

知识点 :

  1. 自查询
  2. 动脑子分析 + 会一步步调试
  3. 聚合函数
  4. 数值函数round
select
    a.machine_id,
    round((sum(b.timestamp - a.timestamp) / count(a.process_id)), 3) as processing_time
from
    Activity as a,
    Activity as b
where
    a.activity_type = 'start' and b.activity_type = 'end'
    and
    a.machine_id = b.machine_id and a.process_id = b.process_id
group by a.machine_id;