8000 Update 1661_Average_Time_of_Process_per_Machine.sql · rajtuts/raj-leetcode-sql-50@e9cc1c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9cc1c6

Browse files
authored
Update 1661_Average_Time_of_Process_per_Machine.sql
1 parent 87cea40 commit e9cc1c6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

2-Basic-Joins/1661_Average_Time_of_Process_per_Machine.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,41 @@
8000
2727

2828
-- Return the result table in any order.
2929

30+
Example 1:
31+
32+
Input:
33+
Activity table:
34+
+------------+------------+---------------+-----------+
35+
| machine_id | process_id | activity_type | timestamp |
36+
+------------+------------+---------------+-----------+
37+
| 0 | 0 | start | 0.712 |
38+
| 0 | 0 | end | 1.520 |
39+
| 0 | 1 | start | 3.140 |
40+
| 0 | 1 | end | 4.120 |
41+
| 1 | 0 | start | 0.550 |
42+
| 1 | 0 | end | 1.550 |
43+
| 1 | 1 | start | 0.430 |
44+
| 1 | 1 | end | 1.420 |
45+
| 2 | 0 | start | 4.100 |
46+
| 2 | 0 | end | 4.512 |
47+
| 2 | 1 | start | 2.500 |
48+
| 2 | 1 | end | 5.000 |
49+
+------------+------------+---------------+-----------+
50+
Output:
51+
+------------+-----------------+
52+
| machine_id | processing_time |
53+
+------------+-----------------+
54+
| 0 | 0.894 |
55+
| 1 | 0.995 |
56+
| 2 | 1.456 |
57+
+------------+-----------------+
58+
Explanation:
59+
There are 3 machines running 2 processes each.
60+
Machine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
61+
Machine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
62+
Machine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
63+
64+
3065
------------------------------------------------------------------------------
3166
3267
-- SQL Schema

0 commit comments

Comments
 (0)
0