I have 2 tables category
and orderrows
The category table structure
id name parent_id
1 c1 null
2 c2 null
3 c3 2
4 c4 1
5 c5 2
6 c6 5
7 c7 5
Orderrow table structure
id category amount
1 1 100
2 6 100
3 5 100
4 4 100
5 3 100
6 2 100
7 7 100
8 2 100
I'm trying to join the 2 tables are get the total amount only on the parent level
Result:
category total
1 200
2 600
Is there a way to write sql in MySQl to obtain the result.
The results basically gets all the parent child relationships and prints the total amount only on parent level.