读书人

询问在一个表中按编号组合数据的有关问

发布时间: 2012-01-24 23:11:55 作者: rapoo

询问在一个表中按编号组合数据的问题
在一个A表中有如下数据

ID title Text
1 taa aa
1 tbb bb
1 tcc cc
2 tdd dd
2 tee ee
2 tff ff

我想实现如下新表
ID taa tbb tcc
1 aa bb cc
2 dd ee ff

是否可以实现?如何实现?


[解决办法]
select
id,
taa=max(case when title='taa' then text end),
tbb=max(case when title='tbb' then text end),
tcc=max(case when title='tcc' then text end)
from [A]
group by id

读书人网 >SQL Server

热点推荐