日期:2014-05-17  浏览次数:20538 次

如何合并数据
ID rodno Operator TestTime 1 2 3 4 5
1 A01P0123-01A 0145 2012-09-11 11:21:14 1 NULL NULL NULL NULL
1 A01P0123-01A 0145 2012-09-11 11:21:14 NULL 1.2 NULL NULL NULL
1 A01P0123-01A 0145 2012-09-11 11:21:14 NULL NULL 0.5 NULL NULL
1 A01P0123-01A 0145 2012-09-11 11:21:14 NULL NULL NULL 1.2 NULL
1 A01P0123-01A 0145 2012-09-11 11:21:14 NULL NULL NULL NULL 0.9


希望得到下面的样式
ID rodno Operator TestTime 1 2 3 4 5
1 A01P0123-01A 0145 2012-09-11 11:21:14 1 1.2 0.5 1.2 0.9

求解答,求高手

------解决方案--------------------
select id,rodno,operator,testime,max(1) aS 1 ,MAX(2) AS 2,MAX(3) AS 3,Max(4) as 4,max(5) as 5
froom ta 
group by id,rodno,operator,testime
------解决方案--------------------
SQL code
select ID,rodno,Operator ,TestTime,max([1]) [1],max([2]) [2],max([3]) [3],max([4]) [4] from  表 group by ID,rodno,Operator ,TestTime

或
select ID,rodno,Operator ,TestTime,sum([1]) [1],sum([2]) [2],sum([3]) [3],sum([4]) [4] from  表 group by ID,rodno,Operator ,TestTime

------解决方案--------------------
SQL code

select id,rodno,operator,testime,sum(isnull ('1',0)) ,sum(isnull ('2',0)),sum(isnull ('3',0)),sum(isnull ('4',0)),sum(isnull ('5',0))
from 表
group by 
 id,rodno,operator,testime

------解决方案--------------------
SQL code
select ID, rodno, Operator, TestTime,
sum(case [1] when null then 0 else [1] end)as [1] , 
sum(case [2] when null then 0 else [2] end)as [2] ,
sum(case [3] when null then 0 else [3] end)as [3] ,
sum(case [4] when null then 0 else [4] end)as [4] ,
sum(case [5] when null then 0 else [5] end)as [5] 
 from  TB  
group by ID, rodno, Operator, TestTime