I have two tables, the first is the following
"Categories"
id name parent_id
1 Food NULL
2 Vegetable 1
3 Fruit 1
4 Tomatoes 2
5 onion 2
6 bananas 3
7 grapes 3
the second table is the following
"amounts"
id amount category_id
1 100 4
2 50 6
3 25 5
4 100 7
5 50 4
6 25 7
Currently categories table are three levels and I want to return all the Categories along with total columns:
Means that sum of the category of level 2 is the total of level 3 and the total of level 2 should was the sum of level 1. I would really appreciate some help Beforehand thank you very much.