根据同一 table 中的另一列拆分 mysql 中的列
split the column in mysql according to another column in the same table
我有以下 table 格式。
Name_of_Car || model || engine_type
VW petrol engine PassatSE || passat || petrol engine
我需要 Select 上述各列中的值,如下所示。
VW passatSE petrol engine .
我需要检查 engine_type
是否存在于 name_of_car
字段中。如果它确实存在,则以 brand name
、model
、engine_type
的格式剥离它 select。我需要从 Name_of_car
列中删除 select。
不能 100% 确定您想要的输出格式,但您可以使用 MySQL [REPLACE][1]
函数清理 Name_of_Car
字段,例如:
SELECT REPLACE (Name_of_Car, engine_type, ': '), model, engine_type
from testcar
要将其全部作为一个字符串获取:
SELECT CONCAT_WS(' ', REPLACE (Name_of_Car, engine_type, ': '), model, engine_type)
FROM testcar
假设您的 table 名字是 testcar
。
我有以下 table 格式。
Name_of_Car || model || engine_type
VW petrol engine PassatSE || passat || petrol engine
我需要 Select 上述各列中的值,如下所示。
VW passatSE petrol engine .
我需要检查 engine_type
是否存在于 name_of_car
字段中。如果它确实存在,则以 brand name
、model
、engine_type
的格式剥离它 select。我需要从 Name_of_car
列中删除 select。
不能 100% 确定您想要的输出格式,但您可以使用 MySQL [REPLACE][1]
函数清理 Name_of_Car
字段,例如:
SELECT REPLACE (Name_of_Car, engine_type, ': '), model, engine_type
from testcar
要将其全部作为一个字符串获取:
SELECT CONCAT_WS(' ', REPLACE (Name_of_Car, engine_type, ': '), model, engine_type)
FROM testcar
假设您的 table 名字是 testcar
。