数据库设计的严重不合理,
都这样的设计,还想性能良好
update tbl_a set rjck = 
(select sum(zmye)/30 from tbl_a 
where zjrq>=2002-09-01  
and zjrq<2002-09-30)    
where zjrq=2002-09-30

解决方案 »

  1.   

    数据库设计的严重不合理,
    都这样的设计,还想性能良好
    update tbl_a set rjck = 
    (select sum(zmye)/30 from tbl_a 
    where zjrq>=2002-09-01  
    and zjrq<2002-09-30)    
    where zjrq=2002-09-30
      

  2.   

    九月根本就没有31号
    update tbl_a a set rjck=(select avg(zmye) from tbl_a b where a.zh=b.zh and  b.zjrq<to_date('30-9-2002','dd-mm-yyyy') group by zh)
      

  3.   

    九月根本就没有31号,更新30号的。
    update tbl_a a set rjck=(select avg(zmye) from tbl_a b where a.zh=b.zh and  b.zjrq<to_date('30-9-2002','dd-mm-yyyy') group by zh) where zjrq=to_date('2002-9-30','yyyy-mm-dd')
      

  4.   

    九月根本就没有31号,更新30号的。
    update tbl_a a set rjck=(select avg(zmye) from tbl_a b where a.zh=b.zh and  b.zjrq<to_date('30-9-2002','dd-mm-yyyy') group by zh) where zjrq=to_date('2002-9-30','yyyy-mm-dd')
      

  5.   

    能解释一下 数据库设计的严重不合理 性 在 哪儿呢? 
    另外用avg在我这儿是不可行的,只能用sum()/天数 而不是记录数计算。