已回。 当然,也可以改用case when 嵌套
create table test
(
a numeric(10,3),
b varchar(10),
c varchar(10)
)
insert into test values(1.1,'3','c')
insert into test values(1.1,'3','c')
insert into test values(1.1,'3','c')
insert into test values(3,'3','c')
insert into test values(4,'4','b')
Go
select c, 'i'=isnull(nullif(convert(varchar,
sum(
case b when '3' then
convert(int,a)
else 0
end
)
) ,'0'),'')
from test
group by c
GODROP TABLE test
GO
create table test
(
a numeric(10,3),
b varchar(10),
c varchar(10)
)
insert into test values(1.1,'3','c')
insert into test values(1.1,'3','c')
insert into test values(1.1,'3','c')
insert into test values(3,'3','c')
insert into test values(4,'4','b')
Go
select c, 'i'=isnull(nullif(convert(varchar,
sum(
case b when '3' then
convert(int,a)
else 0
end
)
) ,'0'),'')
from test
group by c
GODROP TABLE test
GO
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货