私は以下の要件の解決策を試しました。私は、ユニオンを使用して、ピボットし、機能を利用しようとしました
入力:
ID Name Subject 1 james Maths
出力:
ID Name Subject 1 j Maths 1 a Maths 1 m Maths 1 e Maths 1 s Maths
は、ここでは誰も私のクエリを助けることができますか?
私は以下の要件の解決策を試しました。私は、ユニオンを使用して、ピボットし、機能を利用しようとしました
入力:
ID Name Subject 1 james Maths
出力:
ID Name Subject 1 j Maths 1 a Maths 1 m Maths 1 e Maths 1 s Maths
は、ここでは誰も私のクエリを助けることができますか?
MySQLのSubString機能を使用して、1番目、2番目、3番目、...の文字を取得できます。あなたが所望の出力を資料館ために、独自の関数を記述することができるはずです。この例では
SUBSTRING([文字列]、[位置]、[長さ])
例
select ID, SUBSTRING(Name, 1, 1) as Name, Subject from yourtable
。
これは再帰的なクエリで行われますが、これまでのところ、再帰的なクエリはMySQLには含まれていません。
あなたは文字の最大数を知っている場合(例えば7)、あなたが行うことができます
select id, name, subject
from
(
select id, substr(name, 1, 1) as name, subject from mytable
union all
select id, substr(name, 2, 1) as name, subject from mytable
union all
select id, substr(name, 3, 1) as name, subject from mytable
union all
select id, substr(name, 4, 1) as name, subject from mytable
union all
select id, substr(name, 5, 1) as name, subject from mytable
union all
select id, substr(name, 6, 1) as name, subject from mytable
union all
select id, substr(name, 7, 1) as name, subject from mytable
)
where name <> '';