如何在sql 2005中将一列拆分为多列 [英] HOw to split one Column into multiple columns in sql 2005
本文介绍了如何在sql 2005中将一列拆分为多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要基于Reiseion Wise详细信息的数据,例如
col1 col2 col3
穆斯林印度教Ja那教
但我的数据在"
"一列中
穆斯林
印度语
in那教
我该如何实现.请帮助我
Hi,
I need the data based on Religion Wise details like
col1 col2 col3
Muslim Hindu Jain
but my data is in One column like
Muslim
Hindu
Jain
How can i achieve this.Please help me
推荐答案
为此在SQL Server中使用PIVOT
.请查看下面的链接以获取有关此信息的更多信息.
http://msdn.microsoft.com/en-us/library/ms177410.aspx
UsePIVOT
in SQL Server for this. Have a look at below link for more information on this.
http://msdn.microsoft.com/en-us/library/ms177410.aspx
嗨jagadeesh
您的问题有点晦涩难懂,但通常将一个列分成多个列是一种通用方法:
Hi jagadeesh
Your question is somehow obscure but generally to make a column into multiple columns here is a general approach :
select * , 'muslim' col1, '' col2 , '' col3 from table1 where religion='muslim'
union
select * , '' col1, 'hindu' col2 , '' col3 from table1 where religion='hindu'
union
select * , '' col1, '' col2 , 'jain' col3 from table1 where religion='jain'
希望对您有所帮助.
Hope it helps.
这篇关于如何在sql 2005中将一列拆分为多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文