如何使用sql 2008中的视图将行更改为列 [英] How to change rows to colums using view in sql 2008

查看:98
本文介绍了如何使用sql 2008中的视图将行更改为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数据的表A

学生ID主题分数

S001数学40

S001英语60

S002数学66

S002英语43

S003数学78

S003英语30



我想在sql server 2008中创建一个以这种形式表示的视图

StudentID英语数学

S001 60 40

S002 43 66

S003 30 78



有人可以帮帮我吗?

I have table A with this data
StudentID Subject Score
S001 Maths 40
S001 English 60
S002 Maths 66
S002 English 43
S003 Maths 78
S003 English 30

I want to create a view that will represent it in this form in sql server 2008
StudentID English Maths
S001 60 40
S002 43 66
S003 30 78

Can some one help me out?

推荐答案

你可以使用PIVOT查询,

http://msdn.microsoft.com/en-us/library/ms177410(v = sql.100).aspx [ ^ ]



试试你的如果您需要更多帮助,请自行回复我们
You can use PIVOT query,
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.100).aspx[^]

try your self and get back to us if you need any more help


这篇关于如何使用sql 2008中的视图将行更改为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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