create table #abc (id int, a varchar(8), b varchar(8))
drop table #abc
insert into #abc values(1, '姓名', '李')
insert into #abc values(1, '性别', '男')
insert into #abc values(1, '年龄', '20')
insert into #abc values(2, '姓名', '张')
insert into #abc values(2, '性别', '女')
insert into #abc values(2, '年龄', '23')
select max(case a when '姓名' then b else '' end) as 姓名,
max(case a when '性别' then b else '' end) as 性别,
max(case a when '年龄' then b else 0 end) as 年龄
from #abc
group by id
select max(case a when '姓名' then b else '' end) as 姓名,
max(case a when '性别' then b else '' end) as 性别,
max(case a when '年龄' then b else 0 end) as 年龄
from 表
group by id
select max(case a when '姓名' then b else '' end) as 姓名,
max(case a when '性别' then b else '' end) as 性别,
max(case a when '年龄' then b else 0 end) as 年龄
from 表