I have two tables, and i would like to get the sum of the logged minutes for the tasks grouped by tag, most of the time the subtasks have the same tag as the parent but in some cases, they don't.
How can i get the sum of logged minutes grouped by tag, including the subtasks so if they don't have a tag they inherit the tag from their parent.
Task
+-----+-----------+------+-------+------------+
| id | parent-id | name | tag | is-subtask |
+-----+-----------+------+-------+------------+
| 001 | | a | sales | 0 |
| 002 | 001 | b | sales | 1 |
| 003 | 001 | c | | 1 |
| 004 | | d | store | 0 |
+-----+-----------+------+-------+------------+
times
+-----+---------+-------------+----------------+
| id | task-id | description | logged-minutes |
+-----+---------+-------------+----------------+
| 991 | 001 | Time for a | 15 |
| 992 | 002 | Time for ab | 60 |
| 993 | 002 | Time for ab | 75 |
| 994 | 003 | Time for ac | 35 |
| 995 | 004 | Time for d | 20 |
+-----+---------+-------------+----------------+