在sql server 2008中显示行到列 [英] Display row to column in sql server 2008
本文介绍了在sql server 2008中显示行到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
i有我的表中的记录
SchoolCode | 等级类型 | 女孩 | 男孩 |
ABC | 1 | 5 | 12 |
ABC | 2 | 7 > | 14 |
ABC | 3 | 12 | 5 |
ABC | 4 | 14 | 3 |
ABC | 5 | 22 | 1 |
ABC | 6 | 15 | 2 |
ABC | < Ť d> 7 18 | 7 | |
ABC | 8 | 19 | 9 |
我希望得到像
$的结果b $ b SchoolCode Grade1Girls Grade1Boys Grade2Girls Grade2Boys ...达到Grade8Girls Grade8Boys
我该怎么办???
>
请帮帮我
Hello Friends ,
i have record like in my table
SchoolCode | Grade Type | Girls | Boys |
ABC | 1 | 5 | 12 |
ABC | 2 | 7 | 14 |
ABC | 3 | 12 | 5 |
ABC | 4 | 14 | 3 |
ABC | 5 | 22 | 1 |
ABC | 6 | 15 | 2 |
ABC | 7 | 18 | 7 |
ABC | 8 | 19 | 9 |
And i want to get result like
SchoolCode Grade1Girls Grade1Boys Grade2Girls Grade2Boys...up to Grade8Girls Grade8Boys
So what can i do???
please help me
推荐答案
Shingala,
您需要检查旋转/在SQL服务器中取消隐藏。请查看此 http://blog.sqlauthority.com/ 2008/06/07 / sql-server-pivot-and-unpivot-table-examples / [ ^ ]
问候
Pawan
Shingala,
You need to check the pivoting/unpivoting in SQL server. Please check this http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]
Regards
Pawan
您可以使用PIVOT SQL函数来做这个,
以下是一些示例链接,
http://blogs.msdn.com/b/spike/ archive / 2009/03/03 / pivot-tables-in-sql-server-a-simple-sample.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx [ ^ ]
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/ [ ^ ]
祝你好运
Hi,
You can use PIVOT SQL function to do this,
Here are some example links,
http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a-simple-sample.aspx[^]
http://msdn.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx[^]
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]
Best luck
这篇关于在sql server 2008中显示行到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文