日期:2014-05-18  浏览次数:20492 次

急求一条有点麻烦的sql语句!
table
A   B     C
1   a     T
2   b     F
2   e     T
1   k     T

得到数据:
A       B       C
1     a+K     T
2     b+e     F

我只能写到:select   A,sum(b)   group   by   A   不知道第三列怎么得?
其中第三列得出是根据:两值相与


------解决方案--------------------
你这个是不是只要有一个是F都为F啊?
------解决方案--------------------
??
select a,sum(b),min(c) from [Table] group by a
------解决方案--------------------
/*
得到数据:
A B C
1 a+K T
2 b+e F
*/

create function dbo.fun(@a varchar(1000))
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s= ' '
select @s=@s+ '+ '+B from test where A=@a
return stuff(@s,1,1, ' ')
end
go

create table test(A int,B varchar(10),C varchar(10))
insert test select 1, 'a ', 'T '
union all select 2, 'b ', 'F '
union all select 2, 'e ', 'F '
union all select 1, 'K ', 'T '

select distinct A,dbo.fun(A),
case C when 'F ' then 'F ' else 'T ' end
from test

drop function fun
drop table test