๐ป ๋ฌธ์ ์ฃผ์ : 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
'SQL > LeetCode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode][SQL50] #12. Students and Examinations (0) | 2023.11.09 |
---|---|
[LeetCode][SQL50] #11. Employee Bonus (0) | 2023.11.08 |
[LeetCode][SQL50] #9. Rising Temperature (0) | 2023.11.08 |
[LeetCode] (์๋ธ์ฟผ๋ฆฌ, ์กฐ์ธ ์๋) #8. Customer Who Visited but Did Not Make Any Transactions (1) | 2023.11.08 |
[LeetCode][SQL50] #7. Product Sales Analysis I (0) | 2023.11.07 |