In mysql database i've created "Sickness" table:
+--------+---------+---------+-------------+---------+-------------------------------+
| Id_SICK|ID_WORKER| FNAME | LNAME | BEGIN_DATE | END_DATE |
+--------+---------+---------+---------+------------+--------------------+-----------+
| 4 | 26 | ANDREW | WORM |2019-03-19 07:00:00 |2019-03-19 15:00:00 |
+--------+---------+---------+----------------------+--------------------+-----------+
| 5 | 25 | ADAM | GAX |2019-03-21 07:00:00 |2019-03-21 15:00:00 |
+--------+---------+---------+----------------------+--------------------------------+
"Workers" table:
+--------+---------+---------+--
|ID_WORKER | FNAME | LNAME |
+----------+---------+----------
| 25 | ADAM | GAX |
+----------+---------+----------
| 26 | ANDREW | WORM |
+----------+---------+----------
"Orders" table:
+--------+---------+---------+------------+
|ID_ORDER | DESC_ORDER | NUMBER_ORDER |
+----------+---------+--------------------+
| 20 | TEST | TEST |
+----------+---------+--------------------+
And "Order_status" table:
+--------+---------+---------+---------+-------------+--------+----------+------------+
| Id_status|ID_WORKER| ID_ORDER| BEGIN_DATE | END_DATE | ORDER_DONE |
+----------+---------+---------+----------+------------+---------+--------------------+
| 47 | 25 | 20 |2019-03-18 06:50:35 |2019-03-18 15:21:32| NO |
+----------+---------+---------+------------+---------+-------------------+-----------+
| 48 | 25 | 20 |2019-03-20 06:44:12 |2019-03-20 15:11:23| NO |
+----------+---------+---------+------------+---------+-------------------+-----------+
| 50 | 25 | 20 |2019-03-22 06:50:20 |2019-03-22 12:22:33| YES |
+----------+---------+---------+------------+---------+-------------------+-----------+
| 51 | 26 | 20 |2019-03-18 06:45:11 |2019-03-18 15:14:45| NO |
+----------+---------+---------+------------+---------+-------------------+-----------+
| 52 | 26 | 20 |2019-03-20 06:50:22 |2019-03-20 15:10:32| NO |
+----------+---------+---------+------------+---------+-------------------+-----------+
| 53 | 25 | 20 |2019-03-22 06:54:11 |2019-03-22 11:23:45| YES |
+----------+---------+---------+------------+---------+-------------------+-----------+
I would like to sumarize "total time" of each other workers (in order_status table) on the order including with sumarizing "sickness time" from Sickness table. I have selected workers (LNAME, FNAME) orders (DESC_ORDER and NUMBER_ORDER) and "TOTAL TIME" on order from each other workers correctly. But i'm not able to sumarize sickness time. I wrote the mysql command in below:
SELECT workers.FNAME, workers.LNAME, orders.NUMBER_ORDER, orders.DESC_ORDER, SEC_TO_TIME(SUM(TIME_TO_SEC(order_status.END_DATE) - TIME_TO_SEC(order_status.BEGIN_DATE))) AS 'TOTAL TIME', SEC_TO_TIME(SUM(TIME_TO_SEC(sickness.END_DATE) - TIME_TO_SEC(sickness.BEGIN_DATE))) AS 'SICKNESS TIME' FROM order_status INNER JOIN workers ON workers.ID_WORKER = order_status.ID_WORKER INNER JOIN orders ON orders.ID_ORDER = order_status.ID_ORDER INNER JOIN sickness ON sickness.ID_WORKER = workers.ID_WORKER WHERE orders.NUMBER_ORDER LIKE 'TEST' GROUP BY workers.ID_WORKER
Then i've got that result:
+--------+---------+---------+-------+------------+------------+-------------+
| FNAME | LNAME | NUMBER_ORDER | DESC_ORDER | TOTAL TIME | SICKNESS_TIME|
+----------+---------+---------------+------------+------------+-------------+
| ADAM | GAX | TEST | TEST | 22:25:38 | 24:00:00 |
+----------+---------+---------------+------------+------------+-------------+
| ANDREW | WORM | TEST | TEST | 22:52:12 | 24:00:00 |
+----------+---------+---------------+------------+------------+-------------+
As for as "Sickness time is incorrect" because from the "Sickness" after grouping ID_SICK is
+--------+---------+-----+
| Id_SICK| SICKNESS TIME |
+--------+---------+-----+
| 4 | 08:00:00 |
+--------+---------+-----+
| 5 | 08:00:00 |
+--------+---------+-----+
I have sumarize "TOTAL TIME + SICKNESS TIME" too for example
TOTAL TIME: 22:25:38
SICKNESS TIME: 8:00:00
TOTAL + SICKNESS TIME : 22;25:38 + 8:00:00 = 30:25:38
Can someone please help me how to deal with? What kind of mysql query should i write? Any ideas? Thx for any help :)