I have a table having store,combo products sold, quantity sold and sales. This is different from “Reverse GROUP_CONCAT” in MySQL?" question in terms of sales not getting attributed to every product but only to the primary product. For eg. A combo pack of LED TV and sound System has to be broken into LED and Sound system however the sales would be mapped to LED as it is the primary product.
INSERT INTO table(store, product, qty, sales)
VALUES('Store 1', 'Prod l + Prod f', '2', '1000'),
('Store 1', 'Prod a + Prod b + Prod c', '1', '15000'),
('Store 2', 'Prod h + Prod a + Prod y + Prod q', '1', '20000');
I would like to delimit the product column into single products and allocate the sales and quantity to the primary product. I would like the output table to be something like these. I tried this function "regexp_split_to_table" but was unable to do it.
INSERT INTO table(store, product, qty, sales)
VALUES('Store 1', 'Prod l', '2', '1000'),
('Store 1', 'Prod f', '', ''),
('Store 1', 'Prod a', '1', '15000'),
('Store 1', 'Prod b', '', ''),
('Store 1', 'Prod c', '', ''),
('Store 2', 'Prod h + Prod a + Prod y + Prod q', '1', '20000'),
('Store 2', 'Prod a', '', ''),
('Store 2', 'Prod y', '', ''),
('Store 2', 'Prod q', '', '');
Can anyone help me with it please?