如何在sqlserver -2005中交换行和列头
问题描述:
select planttype ,sum(noof50kgsbags*50)[50 Kg],sum(noof70kgsbags*70)[70 Kg]
from K_FeedPlantEntryIndent
WHERE (date BETWEEN '2013-04-01 00:00.000' AND getdate()) AND (attrited = 'True')
group by planttype order by planttype
结果
result
planttype 50 Kg 70 Kg
KJL 353550 2416120
Rohini 56150 220990
Sneha 43950 0
Suguna 1290850 0
我想要的输出是
My desired output is
plantype KJL Rohini Sneha Suguna
50 kg xx xx xx xx
70 Kg x x x xx
任何人都可以建议我怎么做?
Can any one suggest me how to do?
答
您需要使用数据透视来实现此目的。这是一篇包含完整示例的文章:简单易用的方法SQL查询中的数据透视 [ ^ ]
You need to use a pivot to achieve this. Here's an article with a full example for you: Simple Way To Use Pivot In SQL Query[^]