嗨,这可能是一个简单的,但我需要专门为MYsql
提供帮助我有一列中的数据可以调用WORK 1,2,3,5,2列(这些值有时更长,更短或存在更多值,例如12,15,11,15,16,143)
我需要将这些内容放入每个分隔符的1个新列中,并为所显示的订单提供ID。例如输出
答案 0 :(得分:0)
SELECT
*
FROM (SELECT
ROW_NUMBER()
OVER (ORDER BY WORK) AS Row,
RIGHT(LEFT(T.WORK, Number - 1),
CHARINDEX(',', REVERSE(LEFT(',' + T.WORK, Number - 1)))) AS a
FROM master..spt_values,
<YOUR_TABLENAME> T
WHERE Type = 'P'
AND Number BETWEEN 1 AND LEN(T.WORK) + 1
AND (SUBSTRING(T.WORK, Number, 1) = ','
OR SUBSTRING(T.WORK, Number, 1) = '')) AS A