创建表及数据
create table X(A varchar(1),
B varchar(1),
C int,
D int);
insert into X values ('1','x',1,1);
insert into X values ('O','2',1,1);
insert into X values ('1','2',1,1);
执行
select sum(case when A='O' or B='x' then 0 else C end) C,sum(D) D from X
结果
select sum(decode(a,'O',decode(b='X',0,1),1)),sum(s) from x;