使用 SQL 查询根据值复制和拆分行? [英] Duplicate and Split Row based on value by using SQL Query?

查看:29
本文介绍了使用 SQL 查询根据值复制和拆分行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据,想根据列值拆分多行.

I have set of data and wants to split multiple rows based on the column value.

例如

源数据:

预期输出:

谢谢,劳伦斯A

推荐答案

解决上述问题的最佳且最简单的方法是

选择值作为 UID、姓名、年龄、教育、部门

Select value as UID, Name ,Age ,Education ,Department

来自 StackSoln

from StackSoln

交叉应用 string_split(UID,',')

Cross apply string_split(UID,',')

STRING_SPLIT

一个表值函数,它根据指定的分隔符将字符串拆分为子字符串行.

A table-valued function that splits a string into rows of substrings, based on a specified separator character.

交叉申请

仅返回从表值函数生成结果集的外部表中的行.换句话说,CROSS APPLY 的结果不包含任何从右侧表表达式中未获得结果的左侧表表达式行.CROSS APPLY 作为一行一行的 INNER JOIN

returns only rows from the outer table that produce a result set from the table-valued function. It other words, result of CROSS APPLY doesn't contain any row of left side table expression for which no result is obtained from right side table expression. CROSS APPLY work as a row by row INNER JOIN

这篇关于使用 SQL 查询根据值复制和拆分行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆