--查询
select ID
,Col1=max(case Item when 'Col1' then Value end)
,Col2=max(case Item when 'Col2' then Value end)
from 表
group by ID
select ID
,Col1=max(case Item when 'Col1' then Value end)
,Col2=max(case Item when 'Col2' then Value end)
from 表
group by ID
create table 表(ID int,Item varchar(10),Value varchar(10))
insert 表 select 1,'Col1','A'
union all select 1,'Col2','12'
union all select 2,'Col1','A'
union all select 2,'Col2','15'
union all select 3,'Col1','B'
union all select 3,'Col2','12'
union all select 4,'Col1','B'
union all select 4,'Col2','13'
go--查询
select ID
,Col1=max(case Item when 'Col1' then Value end)
,Col2=max(case Item when 'Col2' then Value end)
from 表
group by ID
go--删除测试
drop table 表/*--测试结果
ID Col1 Col2
----------- ---------- ----------
1 A 12
2 A 15
3 B 12
4 B 13(所影响的行数为 4 行)--*/
group by i_id
Col2=max(case Item when 'Col2' then Value end)可否解释这两句是什么意思呢?小弟看不明白。