如何才能直接用sql语句查询出下图的效果呢?
可以借助一个序号表,该表中除了连续的id没有其它字段,id的值范围取决于"一"中存储的信息拆分后的数量。
实现sql:
SELECT NAME, REPLACE( SUBSTRING_INDEX(mobile, &#39;,&#39;, a.id), CONCAT( SUBSTRING_INDEX(mobile, &#39;,&#39;, a.id - 1), &#39;,&#39; ), &#39;&#39; )AS mobile FROM squence a CROSS JOIN( SELECT NAME, CONCAT(mobile, &#39;,&#39;)AS mobile, LENGTH(mobile)- LENGTH(REPLACE(mobile, &#39;,&#39;, &#39;&#39;))+ 1 AS size FROM `user` )b ON a.id <= b.size