SELECT * from (
SELECT id,seq ,SUBSTRING_INDEX(SUBSTRING_INDEX(idList, ';', seq),';' ,-1) idList
FROM (SELECT @rownum:=@rownum+1 AS seq FROM (SELECT @rownum:= 0) r, t_dome LIMIT 0,100) b
CROSS JOIN (
SELECT id,filmIdList idList FROM t_dome
) as similar WHERE seq BETWEEN 1 AND ( SELECT 1 + LENGTH(idList) - LENGTH(REPLACE(idList, ';', '')))
) x WHERE idList > 0
CROSS JOIN 是交叉连接 或者 笛卡尔连接:连接用于从两个或者多个连接表中返回记录集的笛卡尔积,即将左表的每一行与右表的每一行合并。
A和B的合成结果和方式,
A = {1,2}
B = {a,b}
(1,a)(1,b)(2,a)(2,b)
substring_index(字符串,分隔符,序号)
string:用于截取目标字符串的字符串。可为字段,表达式等。
sep:分隔符,string存在且用于分割的字符,比如(,;、.)等。
num:序号,为非0整数。若为整数则表示从左到右数,若为负数则从右到左数。比如www.xxx.com,要获取www字符就即substring_index("www.xxx.com",'.',1)
标签:www,idList,seq,转列,rownum,连接,SELECT From: https://blog.51cto.com/u_15261296/6118374