Here are the table structures
Table A (id, name)
Table B (id, A-id)
Table C (id, quantity, B-id, D-id)
Table D (id, E-id, F-id)
Table E (id, name)
Table F (id, name)
I want to get the result like this
A.name | E.name | F.name | SUM(C.quantity)
-------------------------------------------
foo | aaa | zzz | 50
-------------------------------------------
foo | aaa | xxx | 0
-------------------------------------------
foo | bbb | www | 10
-------------------------------------------
bar | aaa | zzz | 12
-------------------------------------------
bar | aaa | xxx | 1
-------------------------------------------
bar | bbb | www | 30
-------------------------------------------
I have to show all entries in A
, E
, and F
even though there is no entry related to them in C.
So basically I have to group all data in C
by every possible combination of A
, E
, and F
and show 0
if there is no data available in C
.
How do I do that?