表資料如下
ID TYPE T1 T2 T3 T4
1 上海,北京 S B S B
想查詢成下面這樣的
ID TYPE T1 T2 T3 T4
1 上海 S NULL S NULL
1 北京 NULL B NULL B
uj5u.com熱心網友回復:
create table test(id int,ttype varchar(50),t1 varchar(10),t2 varchar(10),t3 varchar(10),t4 varchar(10))insert into test
values(1,'上海,北京','S','B','S','B')
SELECT id,
SUBSTRING_INDEX(SUBSTRING_INDEX(ttype,',',help_topic_id+1),',',-1) AS num
,case when help_topic_id+1 = 1 then t1 else null end as t1
,case when help_topic_id+1 = 2 then t2 else null end as t2
,case when help_topic_id+1 = 1 then t3 else null end as t3
,case when help_topic_id+1 = 2 then t4 else null end as t4
FROM
mysql.help_topic ,test
WHERE
help_topic_id < 2
uj5u.com熱心網友回復:
1 上海 S null S null1 北京 null B null B
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/250329.html
標籤:MySQL
下一篇:R語言做校準度曲線報錯
