如何把一条数据转换成多条数据假如数据库有1条数据:idnamesexage1张三男18读取出来我要把他转成3条如下的
如何把一条数据转换成多条数据
假如数据库有1条数据:
id name sex age
1 张三 男 18
读取出来我要把他转成3条如下的数据应该怎样做:
1 张三
2 男
3 18
[解决办法]
- SQL code
with t(id,name,sex,age) as(select 1,'张三','男','18')select row_number() over(order by getdate()) rn,resultfrom (select convert(varchar(20),name) result from tunion all select convert(varchar(20),sex) from tunion all select convert(varchar(20),age) from t)t1;/*rn result-------------------- --------------------1 张三2 男3 18(3 行受影响)*/
