是否可以将多行转换为单列? [英] Is it possible to convert multiple rows as single column?

查看:75
本文介绍了是否可以将多行转换为单列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将多行转换为单列?

对于Ex,

我有这样的表格,

id name subname标记

1 abc C 10

1 abc JAVA 20

1 abc DAA 30

2 xyz C 30

2 xyz JAVA 20

2 xyz DAA 10

在这种情况下,行应转换为列,子名称只应作为列出现一次像这样的表。



id name C JAVA DAA

1 abc 10 20 30

2 xyz 30 20 10
有可能吗?如果可能请帮助我....

Is it possible to convert multiple rows to single column?
For Ex,
I have table like this,
id name subname marks
1 abc C 10
1 abc JAVA 20
1 abc DAA 30
2 xyz C 30
2 xyz JAVA 20
2 xyz DAA 10
In this case the rows should converted into columns and the subname should come only once as column in the table like this.

id name C JAVA DAA
1 abc 10 20 30
2 xyz 30 20 10
Is it possible? If possible please help me....

推荐答案

是的,你可以做到这一点,你正在寻找的是Pivot关系运营商。



以下是一些链接,可以帮助您学习PIVOT并为您的案例提供解决方案。



CodeProject提示:

在SQL查询中使用Pivot的简单方法 [ ^ ]



http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/ [ ^ ]



https://technet.microsoft.com/en-us/library/ms177410(v = sql.105).aspx [ ^ ]
Yes you can do it and what you are looking for is Pivot relational operator.

Here are some links that help you learn PIVOT and come up with a solution for your case.

CodeProject Tip:
Simple Way To Use Pivot In SQL Query[^]

http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]

https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx[^]


这篇关于是否可以将多行转换为单列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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