select A.code,nvl((select sum(C.a) from C where C.aid = A.aid and C.bid = B.bid ),0) from A,B where A.code = B.code,C表数据可能为空,目前效率很慢,能否优化SQL
解决方案 »
- 不存在的表问什么能查到信息呢?
- sql2005通过odbc向oracle中insert数据报下列错误,请高手指教!
- oracle 字段取别名 后怎么用这个别名???
- 安装oracle11g时出现 先决条件检查全部失败 求高人指点
- 用dba登录可以访问表,用normal登录访问不了,怎么修改权限?
- 请问如何用EXP只导出数据表数据?解决马上给分!
- 帮忙看一下这段什么意思
- OracleOraHome92Agent 启动问题
- 更改字符集数据库不能启动!请高手回答,必送分!
- 帮忙看看,我要怎么在这条sql插入数据,谢谢各路大神了。
- 用PL/SQL 执行不出来结果,小白求助
- 关于学习大数据、数据库开发的学习规划。
select a.a_code,
nvl(sum(c.a), 0)
from (
select A.code a_code,
B.code b_code
from A, B
where A.code = B.code
) a,
c
where a.a_code = c.aid(+)
and a.b_code = c.bid(+)
group by a.a_code
;
此外,C表的连接字段必须有索引,否则这种标量子查询会翻车的
select A.code,nvl(c.sm,0), from A,B,(select aid,bid,sum(C.a) sm from C group by aid,bid ) c
where A.code = B.code
and a.aid=c.aid(+)
and b.bid=c.bid(+);
大概就这样改吧。
exists(select 0 from A where A.aid = C.aid) and
exists(select 0 from B where B.aid = C.aid)
) from A
where exists(select 0 from B where B.code = A.code) ;