declare cursor c2 is select goodsid,sum(amount) amount from t_bill_detail where exists (select bseqid from t_bill_header where billtypeid=12) group by goodsid; begin delete from t_temp_sale; for t2 in c2 loop insert into t_temp_sale (goodsid,amount) values(t2.goodsid,t2.amount); end loop;end;/
内嵌视图:
select t.goodsid,t.name,t.spec,t.factory,h.amount from (select a.goodsid,sum(amount) amount from t_bill_detail a where exists(select bseqid from t_bill_header where billtypeid=12 and a.bseqid=bseqid) group by(a.goodsid)) h, t_goods_info t where t.goodsid=h.goodsid;