select *
from gisductseg
where sign((select nvl(decode(count(c),
0,
0,
sum(decode(sign(24 - c), 1, 1, 0)) / count(c)),
0) cc
from (select count(f.id) c
from giscablesectionrelation cr, gisfiber f
where gisductseg.id = cr.edgeid
and cr.cablesectionid = f.cablesectionid
group by cr.cablesectionid)) - 0.126) = 1
这个sql,在我的数据库里运行结果完全不对甚至在我们的正式库里直接报错,提示gisductseg.id无法找到。create or replace function getUnderUtilizationDuctseg(segid in number) return number is
result number(18,15) ;
begin select nvl(decode(count(c),
0,
0,
sum(decode(sign(24 - c), 1, 1, 0)) / count(c)),
0) into result
from (select count(f.id) c
from giscablesectionrelation cr, gisfiber f
where segid = cr.edgeid
and cr.cablesectionid = f.cablesectionid
group by cr.cablesectionid); return result;
end getUnderUtilizationDuctseg;select * from gisductseg where getUnderUtilizationDuctseg(gisductseg.id)>0.126这样,通过把嵌套提取到function后,结果就是正确的了谁帮忙来解答一下啊,不甚感激
解决方案 »
- 求助,想在Oracle中调取当天数据或者近几天数据,sql语句出现问题,求解决办法。,现将近几天调试状况写一下,希望
- 将表删除后如何回滚
- TNS 配置 SSL 连接方式后,连接不上,请问哪位知道怎么配置SSL连接方式??
- Oracle Forms 代码下载,PL/SQL 代码下载,公司内部研修的时候写的。
- DX请帮忙,由于买书不便,谁有“<<Oracle 9i 中文版数据库系统管理>>赵松涛著 人民邮电出版社” 电子版或网址
- 一个奇怪的问题, 修改系统时间后,再用PLSQL developer就无法查询表.
- oracle initialization or shutdown in progress
- 今天在书上看到的一句话,不懂,盼指教
- 关于数据插入的问题(oracle8)
- 用问怎么样导出指定用户中的一张表?
- 救命啊,已经调用了DAO里面的session.update()方法,但是数据库里面的数据就是不更新,求高手帮忙
- 对于oracle存储过程的一点疑惑
select *
from gisductseg
where sign最开头这里有这个表,在嵌套的最外层
select *
from gisductseg
where sign(
(
select nvl(decode(count(c), 0, 0,
sum(decode(sign(24 - c), 1, 1, 0)) / count(c)
),
0) cc
from (
select count(f.id) c
from giscablesectionrelation cr, gisfiber f ,gisductseg
where gisductseg.id = cr.edgeid
and cr.cablesectionid = f.cablesectionid
group by cr.cablesectionid
) ) - 0.126) = 1 ;
红色部分是你少写的内容。
确实很奇怪呀。把sign去掉,也会有这个错误么。是
我认为这个代码有很大优化的空间
select count(case when count(1)<24 then 1 end)
/count(count(1))
from giscablesectionrelation cr, gisfiber f
where gisductseg.id = cr.edgeid
and cr.cablesectionid = f.cablesectionid
group by cr.cablesectionid)>0.126这样应该就行了吧