Average Time of Process per Machine
<p>Table: <code>Activity</code></p>

<pre>
+----------------+---------+
| Column Name    | Type    |
+----------------+---------+
| machine_id     | int     |
| process_id     | int     |
| activity_type  | enum    |
| timestamp      | float   |
+----------------+---------+
The table shows the user activities for a factory website.
(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.
machine_id is the ID of a machine.
process_id is the ID of a process running on the machine with ID machine_id.
activity_type is an ENUM (category) of type (&#39;start&#39;, &#39;end&#39;).
timestamp is a float representing the current time in seconds.
&#39;start&#39; means the machine starts the process at the given timestamp and &#39;end&#39; means the machine ends the process at the given timestamp.
The &#39;start&#39; timestamp will always be before the &#39;end&#39; timestamp for every (machine_id, process_id) pair.
It is guaranteed that each (machine_id, process_id) pair has a &#39;start&#39; and &#39;end&#39; timestamp.
</pre>

<p>&nbsp;</p>

<p>There is a factory website that has several machines each running the <strong>same number of processes</strong>. Write a solution&nbsp;to find the <strong>average time</strong> each machine takes to complete a process.</p>

<p>The time to complete a process is the <code>&#39;end&#39; timestamp</code> minus the <code>&#39;start&#39; timestamp</code>. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.</p>

<p>The resulting table should have the <code>machine_id</code> along with the <strong>average time</strong> as <code>processing_time</code>, which should be <strong>rounded to 3 decimal places</strong>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 
Activity table:
+------------+------------+---------------+-----------+
| machine_id | process_id | activity_type | timestamp |
+------------+------------+---------------+-----------+
| 0          | 0          | start         | 0.712     |
| 0          | 0          | end           | 1.520     |
| 0          | 1          | start         | 3.140     |
| 0          | 1          | end           | 4.120     |
| 1          | 0          | start         | 0.550     |
| 1          | 0          | end           | 1.550     |
| 1          | 1          | start         | 0.430     |
| 1          | 1          | end           | 1.420     |
| 2          | 0          | start         | 4.100     |
| 2          | 0          | end           | 4.512     |
| 2          | 1          | start         | 2.500     |
| 2          | 1          | end           | 5.000     |
+------------+------------+---------------+-----------+
<strong>Output:</strong> 
+------------+-----------------+
| machine_id | processing_time |
+------------+-----------------+
| 0          | 0.894           |
| 1          | 0.995           |
| 2          | 1.456           |
+------------+-----------------+
<strong>Explanation:</strong> 
There are 3 machines running 2 processes each.
Machine 0&#39;s average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
Machine 1&#39;s average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
Machine 2&#39;s average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
</pre>

[]
["Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)", 'Truncate table Activity', "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'start', '0.712')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'end', '1.52')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'start', '3.14')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'end', '4.12')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'start', '0.55')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'end', '1.55')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'start', '0.43')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'end', '1.42')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'start', '4.1')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'end', '4.512')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'start', '2.5')", "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'end', '5')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef get_average_time(activity: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"mysql": ["Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)"], "mssql": ["create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)"], "oraclesql": ["create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)"], "database": true, "name": "get_average_time", "pythondata": ["Activity = pd.DataFrame([], columns=['machine_id', 'process_id', 'activity_type', 'timestamp']).astype({'machine_id':'Int64', 'process_id':'Int64', 'activity_type':'object', 'timestamp':'Float64'})"], "postgresql": ["Create table If Not Exists Activity (machine_id int, process_id int, activity_type VARCHAR(30) CHECK (activity_type IN ('start', 'end')), timestamp float)\n"], "database_schema": {"Activity": {"machine_id": "INT", "process_id": "INT", "activity_type": "ENUM('start', 'end')", "timestamp": "FLOAT"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']