I have the following db table structure:
division | department | unit | subunit | worker_no | money_data1 | money_data2 | ...
So the table is filled with rows with information about workers and some money related data.
I need to display a hierarchy table that goes "top to bottom" in summing the money data.
The table in the frontend should be structured like so:
The columns would be the sum of all the different money_datas, with rows consiting of all sub-units, from the division, to each individual worker's data.
(So you can go inside each level)
Here is an example:
|money_data1|money_data2|...
--------------------------------------------------|-----------|-----------|
division1_sum | | |
| | |
division1_department1_sum | | |
| | |
division1_1_department1_subunit1_sum | | |
| | |
division1_1_department1_unit1_subunit1_sum | | |
| | |
division1_1_department1_unit1_subunit1_worker1_sum| | |
| | |
division1_1_department1_unit1_subunit1_worker2_sum| | |
In this example I went down all the way from some division to displaying each of the workers consisting of it.
(And of course this division can have many more departments and many more units etc.. and there are a few divisions as well)
Should I:
- Get all the data of individual workers then use PHP to sum each level
- Do something with SQL? Maybe use SQL to sum the main levels and then for individual workers just fetch the data sum with PHP?