/*
drop table tbl_name;
create table tbl_name (ID int ,mSize varchar(100));
insert into tbl_name values (1,'tiny,small,big');
insert into tbl_name values (2,'small,medium');
insert into tbl_name values (3,'tiny,big');
*/
SELECT * from tbl_name
-- 参考:
-- http://cenalulu.github.io/mysql/column-row-reverse/
-- http://www.uncletoo.com/html/mysql/1060.html
SELECT ID,mSize, substring_index(substring_index(m.mSize,',',num),',',-1) splitText
from (
SELECT *,
@row_number := CASE
WHEN @customer_no = id THEN @row_number + 1
ELSE 1
END AS num,
@customer_no := id as idsa
from (
SELECT b.* from (SELECT *, LENGTH(mSize) - LENGTH( REPLACE(mSize,',','') )+ 1 alls from tbl_name) a join (SELECT *, LENGTH(mSize) - LENGTH( REPLACE(mSize,',','') )+ 1 alls from tbl_name) b where a.alls <= b.alls
) s,(SELECT @customer_no := 0,@row_number := 0) as t
) m
drop table tbl_name;
create table tbl_name (ID int ,mSize varchar(100));
insert into tbl_name values (1,'tiny,small,big');
insert into tbl_name values (2,'small,medium');
insert into tbl_name values (3,'tiny,big');
*/
SELECT * from tbl_name
-- 参考:
-- http://cenalulu.github.io/mysql/column-row-reverse/
-- http://www.uncletoo.com/html/mysql/1060.html
SELECT ID,mSize, substring_index(substring_index(m.mSize,',',num),',',-1) splitText
from (
SELECT *,
@row_number := CASE
WHEN @customer_no = id THEN @row_number + 1
ELSE 1
END AS num,
@customer_no := id as idsa
from (
SELECT b.* from (SELECT *, LENGTH(mSize) - LENGTH( REPLACE(mSize,',','') )+ 1 alls from tbl_name) a join (SELECT *, LENGTH(mSize) - LENGTH( REPLACE(mSize,',','') )+ 1 alls from tbl_name) b where a.alls <= b.alls
) s,(SELECT @customer_no := 0,@row_number := 0) as t
) m