获取一列查询作为列名 [英] get one column of query to be the columnname
本文介绍了获取一列查询作为列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个tblProductAttribute与
Hi,i have this tblProductAttribute with
ProductAttributeID|ProductID|AttributeID|AttributeValue|
1|1|Blue
2|2|medium
(AttributeID 1 =颜色,2 =大小)
i希望从这样的精选查询中获得结果
(AttributeID 1 = Color,2= size)
i want to get result from select query like this
ProductName|Color|Size
sampleproduct|Blue|Medium
总之我需要将行数据作为列名
请帮助我。谢谢: - )
in short i need to get row data to be the column name
please help me.thanks :-)
推荐答案
您可以使用PIVOT来实现它。按照此示例中定义的示例:
在SQL查询中使用Pivot的简单方法 [ ^ ]
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-例子/ [ ^ ]
希望它有所帮助。
You can use PIVOT to achieve it. Follow the example as defined in this example:
Simple Way To Use Pivot In SQL Query[^]
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]
Hope it helps.
谢谢你,我明白了使用pivot,但我相信mysql只有group concat函数。
thanks you,i get the idea of using pivot,but i believe that mysql have only group concat function .
谢谢你,我明白了使用pivot,但我相信mysql只有group concat函数。我已经这样做了,但是当我内部连接多个tables时,我的选择查询面临错误。我稍后发布我的查询。
thanks you,i get the idea of using pivot,but i believe that mysql have only group concat function . I have done that,but im facing an error with my select query when i inner join multiple tables.i post my query later.
这篇关于获取一列查询作为列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文