SQL合并语句问题
ID      姓名      科目         分数 
 1         张三      数学         90 
 1         张三      语文         78 
 1         张三      英语         86 
 2         李四      数学         77 
 2         李四      物理         76   
 怎么将字段中相同的纪录合并,使表格变为   
 ID      姓名      科目         分数 
 1         张三      数学         90 
                               语文         78 
                               英语         86 
 2         李四      数学         77 
                               物理         76 
------解决方案--------------------create table tb070205(ID int, 姓名 nvarchar(10), 科目 nvarchar(10),  分数 int) 
 insert into tb070205 
 select 1   , '张三 '  , '数学 ',   90 
 union all select 1   , '张三 '  , '语文 ',   78 
 union all select 1   , '张三 '  , '英语 ',   86 
 union all select 2   , '李四 '  , '数学 ',   77 
 union all select 2   , '李四 '  , '物理 ',   76   
 select isnull(cast(b.ID as varchar(8)), ' ')ID,isnull(b.姓名, ' ')姓名,a.科目,a.分数 from tb070205 a 
 left join (select id,姓名,min(科目)科目 from tb070205 group by id,姓名)b on a.id=b.id and a.姓名=b.姓名 and a.科目=b.科目   
 drop table tb070205
------解决方案--------------------create table T(ID int, 姓名 varchar(10), 科目 varchar(10), 分数 int) 
 insert T select 1,    '张三 ',   '数学 ',   90 
 union all select 1,    '张三 ',   '语文 ',   78 
 union all select 1,    '张三 ',   '英语 ',   86 
 union all select 2,    '李四 ',   '数学 ',   77 
 union all select 2,    '李四 ',   '物理 ',   76 
 go   
 select col=identity(int, 1, 1), * into #T from T 
 order by ID   
 select 
 ID=case when col=(select min(col) from #T where ID=tmp.ID and 姓名=tmp.姓名) then rtrim(col) else  ' ' end, 
 姓名=case when col=(select min(col) from #T where ID=tmp.ID and 姓名=tmp.姓名) then  姓名 else  ' ' end, 
 科目, 分数 
 from #T as tmp   
 --result 
 ID           姓名         科目         分数           
 ------------ ---------- ---------- -----------  
 1            张三         数学         90 
                         语文         78 
                         英语         86 
 4            李四         数学         77 
                         物理         76   
 (5 row(s) affected)
------解决方案--------------------create table tb070205(ID, 姓名 nvarchar(10), 科目 nvarchar(10),  分数 int) 
 insert into tb070205 
 select 1   , '张三 '  , '数学 ',   90 
 union all select 1   , '张三 '  , '语文 ',   78 
 union all select 1   , '张三 '  , '英语 ',   86 
 union all select 2   , '李四 '  , '数学 ',   77 
 union all select 2   , '李四 '  , '物理 ',   76   
 select ID=(case 分数 when (select max(分数) from tb070205 where ID=a.ID and 姓名=a.姓名) then ID else cast( ' ' as char(1)) end), 
 	姓名=(case 分数 when (select max(分数) from tb070205 where ID=a.ID and 姓名=a.姓名) then 姓名 else cast( ' ' as char(1)) end),科目,分数 
 from tb070205 a
------解决方案--------------------