还有你这不会是要求一个SQL语句出来吧~~~
解决方案 »
- delphi7到delphi2010升级碰到问题
- 新手请教:输入一个条件然后再回车,得出结果,如何弄呀?
- wsock API编写文件传输遇到的问题(大家来看看)
- 在RAVE报表中如何进行分组统计?
- fastreport怎样将纸张设置为连续进纸,即针式打印机常用的有两边有孔的那种纸?
- 怎样用listview制作缩略图?急
- 各位大虾!!!快来帮我看看这是什么错?谢谢了!!!!
- 有没有可能使delphi的opendialog不提供删除、拷贝等操作?
- delphi上是怎么样把工具条拖出主窗体,形成另一个窗体的?64分
- 请问各位灵通人士,Win XP 是Win98的升级版还是Win 2000 的升级版(为什么没有服务器版)?
- 怎样判断adotable所连接的表的字段的数据类型
- 光盘加密的问题
不要那么苛刻了,用游标吧,挺简单的
用游标吧
变量定义省略。。
CURSOR cur_a IS
select bh,sl from a
where bh in
( select bh from a
minus
select bh from b);
begin
open cur_a;
loop
FETCH cur_ar INTO v_bh,v_sl;
EXIT WHEN cur_a%NOTFOUND;
select count(*) into v_bz from c where bh = v_bh;
if v_bz < 1 then
insert into c(bh ,sl) values(v_bh ,(0 -v_sl));
else
update c set sl =sl-v_sl where bh = v_bh;
end if;
delete from a where bh = v_bh;
end loop;
close cur_a;
end ;
set sl=c.sl-a.sl
from c,a
where c.id=a.id
and a.id not in (select id from b)insert c (id,sl)
select id,-sl from a
where a.id not in (select id from b)
and a.id not in (select id from c)delete a
where id not in (select id from b)
如果数据很多,这些语句应该可以优化,数据少的话就不必了!
那我该怎样写。
bh+cbh+dbh 才确定是这条记录。
其中
bh,是int类型, cbh, dbh是字符类型
是不是通过convert写, 可以连起来吗? 这个小问题解决,立即放分。谢谢各位高手,真是太感谢了。
set sl=c.sl-a.sl
from c,a
where c.bh=a.bh and c.cbh=a.cbh and c.dbh=a.dbh
and not exists (select 1 from b where
b.bh=a.bh and b.cbh=a.cbh and b.dbh=a.dbh)insert c (bh,cbh,dbh,sl)
select bh,cbh,dbh,-sl from a
where not exists (select 1 from b where
b.bh=a.bh and b.cbh=a.cbh and b.dbh=a.dbh)
and not exists (select 1 from c where
c.bh=a.bh and c.cbh=a.cbh and c.dbh=a.dbh)delete a
where not exists (select 1 from b where
b.bh=a.bh and b.cbh=a.cbh and b.dbh=a.dbh)其实,也可以用convert(varchar(10),c.bh)+'|'+rtrim(c.cbh)+'|'+rtrim(c.dbh)代替c.id,但是这样写太麻烦,而且效率低。