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呢?我在查询分析器中都有结果啊

解决方案 »

  1.   

    先Debug一下,看一下strsql1的值。
    在sqlplus里执行以下这个值,看看有没有结果。我怀疑是你SQL拼接的不对,或者是你的中文字段和表名称所引起的编码问题。另外,我很佩服你的中文字段名。
    太爱国了,我都无地自容了。
    呵呵,玩笑!
      

  2.   

    貌似是JAVA程序,应该与你这个SQL没有关系的吧。
    有很多人碰到过这个问题,应该是你的DataSet没有Fill进数据(表),所以会报找不到表的错误。
      

  3.   

    我调试过了,在sqlplus里面也是有值的,而且我用别的sql语句去验证,都好使,就这个语句不行,有人能告诉我为什么吗?谢谢!
      

  4.   

    把语句 用 system.out.println打印拼接出来,直接黏贴到plsqldev中运行。 看看有没有数据。 
    要完整的拼接。 
      

  5.   

    Console.WriteLine(strsql1.ToString());
    把语句打出来,然后在命令行里执行一下,就知道哪里出错了。另外,强烈反对使用中文字段名,后患挺多。
      

  6.   

    我不知道怎么把, strsql1在项目打印出来,好像在里面这句,没有办法执行出来!
    至于strssql1的语句,我在调试的时候将其中的语句,复制到PL/SQL中运行,是有结果的我就不知道怎么回事了啊?
      

  7.   


    on hz2.类型=hz.类型) k
    给from之后的集合一个名称先~
      

  8.   

    大概是这样(
    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.类型
    )
      

  9.   

    另外,貌似不是java。
    java的话,倒是有个StringBuffer但是append函数不是开头大写的。
    还有上面代码的strtime是变量,我图省事
      

  10.   

    首先,上面的这个SQL,
    你能执行成功吗?
    那个strtime的值是什么?
    如果代入了strtime的值也可以正常检索。
    那么,就是我和上面一位大哥说的问题了。
    中文字段名
      

  11.   

    那个sql可以执行成功;
    现在我把括号改变了一下位置就没有出现那个错误了;
    就是下面这样:
    (
    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.类型
    )
      

  12.   

    发错了,是这样:(
    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.类型
      
      
      ))
      

  13.   

    现在我又想问问:如何把前两个表合成一个表,再和下面的第三个表相连,如这位兄弟所说:
    [img=C:\Documents and Settings\user1\桌面\QQ截图未命名.png]
      

  14.   

    left join 呗。或者left outer join要么做零时表,然后去更新零时表去
      

  15.   

    哎,基本调试信息给出来,程序不是写出来的,是COPY PASTE出来的,调试是很重要的
      

  16.   

     dba04.ny='" + strtime + "' "这段你的ny是date类型吗,而你的strtime明显是字符串。
     建议你采用绑定变量,或者改成 dba04.ny=to_date(" + strtime + ",'yyyy-mm-dd hh24:mi:ss),坦白说这样写代码,后来负责维护的人一定很痛苦。另外如果你的字段名是汉字的话,最好用双引号括起来,例如select distinct jxtype as "类型"