select 
    (
       select operprice_0  from 
       (
              select t.operprice_0  from 
             (            
                 select stb.bloperdate,stb.depotid,std.mlid,std.operprice_0 
                 from sto_t_blmaster stb,sto_t_bldetail std,sto_t_blsort sts
                 where stb.id=std.masterid
                 and stb.blsortid=sts.id
                 and sts.belongto='01'
                 and stb.staoper='2'
             ) t
             where
              t.depotid=abc.depotid
              and t.mlid=abc.mlid
              order by t.bloperdate desc
        ) where rownum=1
  )  as b
 from sto_v_storagebak abc  
 where
    abc.depotid=1718 and abc.mlid=19372
    and abc.bakyear=2009 and abc.bakmonth=07
用上面语句查询时,b的值为0
改为下面查时
select 
    (
       select operprice_0  from 
       (
              select t.operprice_0  from 
             (            
                 select stb.bloperdate,stb.depotid,std.mlid,std.operprice_0 
                 from sto_t_blmaster stb,sto_t_bldetail std,sto_t_blsort sts
                 where stb.id=std.masterid
                 and stb.blsortid=sts.id
                 and sts.belongto='01'
                 and stb.staoper='2'
             ) t
             where
              t.depotid=1718
              and t.mlid=19372
              order by t.bloperdate desc
        ) where rownum=1
  )  as b
 from sto_v_storagebak abc  
 where
    abc.depotid=1718 and abc.mlid=19372
    and abc.bakyear=2009 and abc.bakmonth=07
出来的是具体的值其实出来的就是具体的值,但是不知道为什么用第一种查出来的一直是0,想不明白呀,望高手指点.

解决方案 »

  1.   

    select t.operprice_0  from 
                (            
                    select stb.bloperdate,stb.depotid,std.mlid,std.operprice_0 
                    from sto_t_blmaster stb,sto_t_bldetail std,sto_t_blsort sts 
                    where stb.id=std.masterid 
                    and stb.blsortid=sts.id 
                    and sts.belongto='01' 
                    and stb.staoper='2' 
                ) t 
                where 
                  t.depotid=abc.depotid 
                  and t.mlid=abc.mlid 
                  order by t.bloperdate desc 
            ) where rownum=1 
     select t.operprice_0  from 
                (            
                    select stb.bloperdate,stb.depotid,std.mlid,std.operprice_0 
                    from sto_t_blmaster stb,sto_t_bldetail std,sto_t_blsort sts 
                    where stb.id=std.masterid 
                    and stb.blsortid=sts.id 
                    and sts.belongto='01' 
                    and stb.staoper='2' 
                ) t 
                where 
                  t.depotid=1718 
                  and t.mlid=19372 
                  order by t.bloperdate desc 
            ) where rownum=1 
    这两个查询出来应该不一样
      

  2.   

    具体的值是什么意思
    std.operprice_0没有为0的值吗?
      

  3.   

    select t.operprice_0  from 
                (            
                    select stb.bloperdate,stb.depotid,std.mlid,std.operprice_0 
                    from sto_t_blmaster stb,sto_t_bldetail std,sto_t_blsort sts 
                    where stb.id=std.masterid 
                    and stb.blsortid=sts.id 
                    and sts.belongto='01' 
                    and stb.staoper='2' 
                ) t ,sto_v_storagebak abc  
                where 
                  t.depotid=abc.depotid 
                  and t.mlid=abc.mlid 
                  order by t.bloperdate desc 
    运行这个看看
      

  4.   


    where 
                  t.depotid=abc.depotid 
                  and t.mlid=abc.mlid 
                  order by t.bloperdate desc 
    这里面完全等于连接的时候 有不匹配的。有那个ID对应不上。
      

  5.   

    第一个查询应该没有值
     t.depotid=abc.depotidand t.mlid=abc.mlid
    这里取不到abc.mlid的值。