strsql1.Append("(select 类型,井口数量,比例,日产液,日产油,含水, 沉没度,采聚度,目前日产液,目前日产油,目前含水,目前沉没度,目前采聚度 from ");
/*井口类型*/
strsql1.Append("((select distinct jxtype as 类型,count(JH) as 井口数量,round(count(JH)/(select count(JH) from wellbd)*100,2) as 比例 from wellbd group by jxtype) hz ");
/*高峰*/
strsql1.Append("left join ");
strsql1.Append("(select distinct jxtype as 类型,round(avg(lowrcyel),1) as 日产液,round(avg(lowrcyl),1) as 日产油,round(avg(lowhs),1) as 含水, round(avg(lowcmd),1) as 沉没度,round(sum(lowccjhwnd*lowrcyel)/sum(lowrcyel),1) as 采聚度 from wellbd ");
strsql1.Append("where wellbd.lowrcyl>0 group by jxtype) hz1 ");
strsql1.Append("on hz.类型=hz1.类型) ");
/*目前*/
strsql1.Append("left join ");
strsql1.Append("(select distinct jxtype as 类型,round(avg(dba04.rcyl+dba04.rcsl),1) as 目前日产液,round(AVG(dba04.rcyl),1) as 目前日产油,round(AVG(round((1-dba04.rcyl/(dba04.rcyl+dba04.rcsl))*100,2)),1) as 目前含水,round(AVG(bs-dym),1) as 目前沉没度,");
strsql1.Append("round(sum(dba04.ccjhwnd*(dba04.rcyl+dba04.rcsl))/sum(dba04.rcyl+dba04.rcsl),1) as 目前采聚度 from dba04,wellbd ");
strsql1.Append("where dba04.jh=wellbd.jh and dba04.rcyl>0 and dba04.ny='" + strtime + "' ");
strsql1.Append("group by jxtype) hz2 ");
strsql1.Append("on hz2.类型=hz.类型) ");我想问为什么无法找到表0呢?我在查询分析器中都有结果啊
/*井口类型*/
strsql1.Append("((select distinct jxtype as 类型,count(JH) as 井口数量,round(count(JH)/(select count(JH) from wellbd)*100,2) as 比例 from wellbd group by jxtype) hz ");
/*高峰*/
strsql1.Append("left join ");
strsql1.Append("(select distinct jxtype as 类型,round(avg(lowrcyel),1) as 日产液,round(avg(lowrcyl),1) as 日产油,round(avg(lowhs),1) as 含水, round(avg(lowcmd),1) as 沉没度,round(sum(lowccjhwnd*lowrcyel)/sum(lowrcyel),1) as 采聚度 from wellbd ");
strsql1.Append("where wellbd.lowrcyl>0 group by jxtype) hz1 ");
strsql1.Append("on hz.类型=hz1.类型) ");
/*目前*/
strsql1.Append("left join ");
strsql1.Append("(select distinct jxtype as 类型,round(avg(dba04.rcyl+dba04.rcsl),1) as 目前日产液,round(AVG(dba04.rcyl),1) as 目前日产油,round(AVG(round((1-dba04.rcyl/(dba04.rcyl+dba04.rcsl))*100,2)),1) as 目前含水,round(AVG(bs-dym),1) as 目前沉没度,");
strsql1.Append("round(sum(dba04.ccjhwnd*(dba04.rcyl+dba04.rcsl))/sum(dba04.rcyl+dba04.rcsl),1) as 目前采聚度 from dba04,wellbd ");
strsql1.Append("where dba04.jh=wellbd.jh and dba04.rcyl>0 and dba04.ny='" + strtime + "' ");
strsql1.Append("group by jxtype) hz2 ");
strsql1.Append("on hz2.类型=hz.类型) ");我想问为什么无法找到表0呢?我在查询分析器中都有结果啊
在sqlplus里执行以下这个值,看看有没有结果。我怀疑是你SQL拼接的不对,或者是你的中文字段和表名称所引起的编码问题。另外,我很佩服你的中文字段名。
太爱国了,我都无地自容了。
呵呵,玩笑!
有很多人碰到过这个问题,应该是你的DataSet没有Fill进数据(表),所以会报找不到表的错误。
要完整的拼接。
把语句打出来,然后在命令行里执行一下,就知道哪里出错了。另外,强烈反对使用中文字段名,后患挺多。
至于strssql1的语句,我在调试的时候将其中的语句,复制到PL/SQL中运行,是有结果的我就不知道怎么回事了啊?
on hz2.类型=hz.类型) k
给from之后的集合一个名称先~
select 类型,井口数量,比例,日产液,日产油,含水, 沉没度,采聚度,目前日产液,目前日产油,目前含水,目前沉没度,目前采聚度
from (
(select distinct jxtype as 类型,
count(JH) as 井口数量,
round(count(JH)/(select count(JH) from wellbd)*100,2) as 比例
from wellbd group by jxtype) hz
left join
(select distinct jxtype as 类型,
round(avg(lowrcyel),1) as 日产液,
round(avg(lowrcyl),1) as 日产油,
round(avg(lowhs),1) as 含水,
round(avg(lowcmd),1) as 沉没度,
round(sum(lowccjhwnd*lowrcyel)/sum(lowrcyel),1) as 采聚度
from wellbd where wellbd.lowrcyl>0 group by jxtype) hz1
on hz.类型=hz1.类型
)
left join
(select distinct jxtype as 类型,
round(avg(dba04.rcyl+dba04.rcsl),1) as 目前日产液,
round(AVG(dba04.rcyl),1) as 目前日产油,
round(AVG(round((1-dba04.rcyl/(dba04.rcyl+dba04.rcsl))*100,2)),1) as 目前含水,
round(AVG(bs-dym),1) as 目前沉没度,
round(sum(dba04.ccjhwnd*(dba04.rcyl+dba04.rcsl))/sum(dba04.rcyl+dba04.rcsl),1) as 目前采聚度
from dba04,wellbd
where dba04.jh=wellbd.jh
and dba04.rcyl>0
and dba04.ny='strtime'
group by jxtype)
hz2 on hz2.类型=hz.类型
)
java的话,倒是有个StringBuffer但是append函数不是开头大写的。
还有上面代码的strtime是变量,我图省事
你能执行成功吗?
那个strtime的值是什么?
如果代入了strtime的值也可以正常检索。
那么,就是我和上面一位大哥说的问题了。
中文字段名
现在我把括号改变了一下位置就没有出现那个错误了;
就是下面这样:
(
select 类型,井口数量,比例,日产液,日产油,含水, 沉没度,采聚度,目前日产液,目前日产油,目前含水,目前沉没度,目前采聚度
from (
(select distinct jxtype as 类型,
count(JH) as 井口数量,
round(count(JH)/(select count(JH) from wellbd)*100,2) as 比例
from wellbd group by jxtype) hz
left join
(select distinct jxtype as 类型,
round(avg(lowrcyel),1) as 日产液,
round(avg(lowrcyl),1) as 日产油,
round(avg(lowhs),1) as 含水,
round(avg(lowcmd),1) as 沉没度,
round(sum(lowccjhwnd*lowrcyel)/sum(lowrcyel),1) as 采聚度
from wellbd where wellbd.lowrcyl>0 group by jxtype) hz1
on hz.类型=hz1.类型
)
left join
(select distinct jxtype as 类型,
round(avg(dba04.rcyl+dba04.rcsl),1) as 目前日产液,
round(AVG(dba04.rcyl),1) as 目前日产油,
round(AVG(round((1-dba04.rcyl/(dba04.rcyl+dba04.rcsl))*100,2)),1) as 目前含水,
round(AVG(bs-dym),1) as 目前沉没度,
round(sum(dba04.ccjhwnd*(dba04.rcyl+dba04.rcsl))/sum(dba04.rcyl+dba04.rcsl),1) as 目前采聚度
from dba04,wellbd
where dba04.jh=wellbd.jh
and dba04.rcyl>0
and dba04.ny='strtime'
group by jxtype)
hz2 on hz2.类型=hz.类型
)
select 类型,井口数量,比例,日产液,日产油,含水, 沉没度,采聚度,目前日产液,目前日产油,目前含水,目前沉没度,目前采聚度
from
(
(select distinct jxtype as 类型,
count(JH) as 井口数量,
round(count(JH)/(select count(JH) from wellbd)*100,2) as 比例
from wellbd group by jxtype) hz
left join
(select distinct jxtype as 类型,
round(avg(lowrcyel),1) as 日产液,
round(avg(lowrcyl),1) as 日产油,
round(avg(lowhs),1) as 含水,
round(avg(lowcmd),1) as 沉没度,
round(sum(lowccjhwnd*lowrcyel)/sum(lowrcyel),1) as 采聚度
from wellbd where wellbd.lowrcyl>0 group by jxtype) hz1
on hz.类型=hz1.类型
left join
(select distinct jxtype as 类型,
round(avg(dba04.rcyl+dba04.rcsl),1) as 目前日产液,
round(AVG(dba04.rcyl),1) as 目前日产油,
round(AVG(round((1-dba04.rcyl/(dba04.rcyl+dba04.rcsl))*100,2)),1) as 目前含水,
round(AVG(bs-dym),1) as 目前沉没度,
round(sum(dba04.ccjhwnd*(dba04.rcyl+dba04.rcsl))/sum(dba04.rcyl+dba04.rcsl),1) as 目前采聚度
from dba04,wellbd
where dba04.jh=wellbd.jh
and dba04.rcyl>0
and dba04.ny='201005'
group by jxtype) hz2 on hz2.类型=hz.类型
))
[img=C:\Documents and Settings\user1\桌面\QQ截图未命名.png]
建议你采用绑定变量,或者改成 dba04.ny=to_date(" + strtime + ",'yyyy-mm-dd hh24:mi:ss),坦白说这样写代码,后来负责维护的人一定很痛苦。另外如果你的字段名是汉字的话,最好用双引号括起来,例如select distinct jxtype as "类型"