0

我试图仅在津贴为零时显示费用,而我的另一个问题是,如果我在津贴栏中有多个零,我只想将这些费用相加。不为零的那个我不想将它们包括在总和中。

Allowa  charges
-----------------------------------------------
84.27   90  0   188428752   2012-05-17 00:00:00
0       100 0   188428752   2013-08-08 00:00:00
84.27   90  0   188428752   2012-06-14 00:00:00
124.7   130 0   188428752   2012-05-10 00:00:00
90.79   90  0   188428752   2012-08-09 00:00:00
90.79   100 0   188428752   2012-10-11 00:00:00
90.79   100 0   188428752   2013-05-23 00:00:00

费用应为 100

Allowa  charges
-------------------------------------------------
  0       100     188428752   2013-08-08 00:00:00
  0       90      188428752   2012-06-14 00:00:00
  90.79   100 0   188428752   2012-10-11 00:00:00
  90.79   100 0   188428752   2013-05-23 00:00:00

收费应该是190。

这个 pl/sql 只给了我总和。

create or replace procedure summary
as
cursor c1
is
select allowance,sum(charges) CH,sum(not_paid) np ,patientid
from claims1 a, claim_details b
where a.claimid = b.claimid
group by allowance, charges,not_paid,patientid;

ins_bal number(9,2);
pat_bal number(9,2);

begin

for a1 in c1 loop

if a1.allowance = 0 then
ins_bal:=a1.CH;
end if;

if a1.allowance != 0 then
 pat_bal:=a1.np;
end if;

insert into summary_hold values(ins_bal,pat_bal,a1.patientid);
commit;

end loop;
end;
/

 This is the final pl/sql
create or replace procedure summary
as
cursor c1
is
select allowance,(case nvl(allowance,0)  when 0 then sum(charges) else 0 end)CH,
(case when nvl(not_paid,0) <> 0 then sum(not_paid) else 0 end) np,patientid,datefrom
from claims1 a, claim_details b
where a.claimid = b.claimid
group by allowance, charges,not_paid,patientid,datefrom;


begin

for a1 in c1 loop

insert into summary_hold values(a1.ch,a1.np,a1.patientid);
commit;

end loop;
end;
/
4

1 回答 1

2

只需使用 CASE 语句。sum(case Allowa when 0 then charges else 0 end).

于 2013-09-20T18:23:32.687 回答