(将actaul数据转换为示例数据) 这是我的表 -
CREATE TABLE `table1` (
`col1` int(11) NOT NULL AUTO_INCREMENT,
`col2` text,
)
ENGINE=InnoDB AUTO_INCREMENT=1129311 DEFAULT CHARSET=utf8
col1 col2
1 abc,xyx,lmn
在sql查询中需要帮助以获得以下格式的输出
col1 col2
1 abc
1 xyz
1 lmn
尝试下面但没有奏效
SELECT A.col1,
Split.a.value(',', 'VARCHAR(10)') AS STRING
FROM (SELECT sources, CAST ('<M>' + REPLACE(col2, ',', '</M><M>') + '</M>' AS XML) AS STRING
FROM table1) AS A CROSS APPLY String.nodes ('/M') AS Split(a)
WHERE A.col1=1;