I've interesting scenario where a summary is required by division except one division which need to shared with other division. An example data is shown below. MAI need to be split with other divisions whereever the numberic number matches with other parts of the codes. Hope this claries. Should anyone need more clarifications, please let me know. How can I've a SQL query logic to get this result?
div code value
ELE ELE40040000 250
MAI MAI40040000 150
MAI MAI40740000 200
MAI MAI43010000 300
PCE PCE40740000 400
REN REN43010000 100
Result
ELE ELE40040000 250
MAI40040000 150
total ELE 400
PCE PCE40740000 400
MAI40740000 200
Total PCE 600
REN REN43010000 100
MAI43010000 300
Total REN 400
Many Thanks in Advance.
div code value
ELE ELE40040000 250
MAI MAI40040000 150
MAI MAI40740000 200
MAI MAI43010000 300
PCE PCE40740000 400
REN REN43010000 100
Result
ELE ELE40040000 250
MAI40040000 150
total ELE 400
PCE PCE40740000 400
MAI40740000 200
Total PCE 600
REN REN43010000 100
MAI43010000 300
Total REN 400
Many Thanks in Advance.