日期:2014-05-16 浏览次数:20441 次
--用js轉呀?
with t(LeafClass,c1,c2,property,value) as(
select 1,'xxx','xx','name','leaf1'
union select 1,'xxx','xx','color','red'
union select 2,'xxxx','xxxxx','height','1000'
)
select LeafClass,c1,c2,isnull(name,'') name,isnull(color,'') color,isnull(height,'') height from t
pivot(max(value) for property in(name,color,height)) a;
/*
LeafClass c1 c2 name color height
----------- ---- ----- ----- ----- ------
1 xxx xx leaf1 red
2 xxxx xxxxx 1000
(2 row(s) affected)
*/
------解决方案--------------------
这数据库的东西吧,怎么放js版块来了
一种是查询出所有记录后另外写代码进行遍历处理,这个好写
另一种是数据库内进行,sqlserver的话可以用游标实现这个转换
------解决方案--------------------
读取到数组里就好了