Diviser une chaîne en colonnes :
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;
Si vous pouvez modifier le design du tableau, il est préférable de créer plusieurs colonnes :
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);