I've got a table "products" which consists of two columns: id, raw
Example:
| id | raw |
|---|---|
| 132 | Description: mangoes; Cost: 15-30; Saving: 64; ER: E 51; EnR: D 56; Eligible: Y$ $ Description: oranges; Cost: 1,000-1,400; Saving: 41; ER: C 75; EnR: D 58; Eligible: Y |
| 497 | Description: bananas; Cost: 25; Saving: 9; ER: E 52; EnR: D 56; Eligible: N$ $ Description: apples; Cost: 4,000-14,000; Saving: 165; ER: E 47; EnR: E 53; Eligible: Y$ $ Description: pears; Cost: 800-1,200; Saving: 393; ER: C 73; EnR: D 55; Eligible: Y |
This table needs to be converted to the final view like this:
| id | Description | Cost | Saving | ER | EnR | Eligible |
|---|---|---|---|---|---|---|
| 132 | mangoes | 15-30 | 64 | E 51 | D 56 | Y |
| 132 | oranges | 1,000-1,400 | 41 | C 75 | D 58 | Y |
| 497 | bananas | 25 | 9 | E 52 | D 56 | N |
| 497 | apples | 4,000-14,000 | 165 | E 47 | E 53 | Y |
| 497 | pears | 800-1,200 | 393 | C 73 | D 55 | Y |
I supposed to do that by the next steps:
- using SPLIT() by '$ $ ' to split each 'raw' string to rows
- using SPLIT() by ';' to split each row from the previous step to separate column and name it.
But I finally confused how to do that.
Could anyone suggest the solution or more elegant way to realize that?
I think the solution is on the surface, but I can't seem to get to it. Thanks.