๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SQL/LeetCode

[LeetCode][SQL50] #10. Average Time of Process per Machine

by ์ด๋ฎด 2023. 11. 8.
728x90

๐Ÿ’ป ๋ฌธ์ œ ์ฃผ์†Œ : Average Time of Process per Machine - LeetCode

 

Average Time of Process per Machine - LeetCode

Can you solve this real interview question? Average Time of Process per Machine - Table: Activity +----------------+---------+ | Column Name | Type | +----------------+---------+ | machine_id | int | | process_id | int | | activity_type | enum | | timestam

leetcode.com

 

๐Ÿ’ป ๋ฌธ์ œ

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places. Return the table in any order.

- machine_id๋ณ„ ํ‰๊ท  processing_time์„ ๊ตฌํ•˜์‹œ์˜ค. processing_time์€ ์†Œ์ˆ˜์  ์„ธ ์ž๋ฆฌ์ˆ˜๊นŒ์ง€ ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•˜๋ฉฐ, ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ƒ๊ด€ ์—†์Šต๋‹ˆ๋‹ค.

 

* processing_time : (end timestamp - start timestamp)

 

๐Ÿ’ป ์ฝ”๋“œ ๋ฐ ํ’€์ด 

select a1.machine_id, round(avg(a2.timestamp-a1.timestamp), 3) as processing_time
from Activity a1, Activity a2
where a1.machine_id = a2.machine_id and a1.process_id = a2.process_id and a1.activity_type = 'start' and a2.activity_type = 'end'
group by a1.machine_id

 

728x90
๋ฐ˜์‘ํ˜•