Opdel en streng i kolonner:
select date,
substring_index(cost, '-', 1) type_a,
case when cost regexp '.*-' then
substring_index(substring_index(cost, '-', 2), '-', -1)
else ''
end type_b,
case when cost regexp '.*-.*-' then
substring_index(substring_index(cost, '-', 3), '-', -1)
else ''
end type_c,
case when cost regexp '.*-.*-.*-' then
substring_index(substring_index(cost, '-', 4), '-', -1)
else ''
end type_d,
case when cost regexp '.*-.*-.*-.*-' then
substring_index(substring_index(cost, '-', 5), '-', -1)
else ''
end type_e
from rate_cost;
Hvis du kan ændre tabeldesignet, er det bedre at oprette flere kolonner:
create table rate_cost (
id int,
rate int,
hotel int,
cost_type_a int,
cost_type_b int,
cost_type_c int,
cost_type_d int,
cost_type_e int,
date date);