2017-12-22 1 views

答えて

1

MySQLのSubString機能を使用して、1番目、2番目、3番目、...の文字を取得できます。あなたが所望の出力を資料館ために、独自の関数を記述することができるはずです。この例では

SUBSTRING([文字列]、[位置]、[長さ])

select ID, SUBSTRING(Name, 1, 1) as Name, Subject from yourtable 

0

これは再帰的なクエリで行われますが、これまでのところ、再帰的なクエリは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 <> ''; 
関連する問題