看不懂,这样的SQL能执行吗?
select zhth, yf, hkje
from (
       select zhth, substr(hksj, 1, 6) as yf, sum(hkje) as hkje
       from t_htxx_hkxx
       group by zhth, substr(hksj, 1, 6)
      )
       )
where yf <= a.yf and zhth = a.zhth) as hklj 
      from (
      select zhth, yf, hkje
      from (select zhth,substr(hksj,1,6) as yf,sum(hkje) as hkje
           from t_htxx_hkxx
           group by zhth,substr(hksj,1,6)
           )
) a

解决方案 »

  1.   

    select zhth, yf, hkje, 
           (select sum(hkje) 
            from (select zhth, yf, hkje 
                  from (select zhth, substr(hksj,1,6) as yf, sum(hkje) as hkje  
                        from t_htxx_hkxx 
                        group by zhth, substr(hksj,1,6)
                        )
                  ) 
            where yf <= a.yf and zhth = a.zhth) as hklj 
    from (select zhth, yf, hkje 
          from (select zhth, substr(hksj,1,6) as yf, sum(hkje) as hkje 
                from t_htxx_hkxx   
                group by zhth, substr(hksj,1,6)
                )
          ) a 
    ;
    对不起贴子贴错了,上面的是要问的sql语句
    这个语句在oracle8上可以执行,在oracle9 ora_00979 不是 group by 表达式
      

  2.   

    try:select a.zhth, a.yf, a.hkje, sum(b.hkje) as hklj 
    from (select zhth, yf, hkje 
          from (select zhth, substr(hksj,1,6) as yf, sum(hkje) as hkje 
                from t_htxx_hkxx   
                group by zhth, substr(hksj,1,6)
                )
          ) a ,
         (select zhth, yf, hkje 
                  from (select zhth, substr(hksj,1,6) as yf, sum(hkje) as hkje  
                        from t_htxx_hkxx 
                        group by zhth, substr(hksj,1,6)
                        )
          ) b 
    where b.yf <= a.yf and b.zhth = a.zhth
      

  3.   

    oracle8 和 oracle9 在 group by 的语法上有什么差异吗?
      

  4.   

    应该是分组函数与子查询的解析的差异,
    sum?SELECT a.*, SUM(hkje)over(PARTITION BY zhth ORDER BY yf ) hkje_s
    FROM (
    select zhth, substr(hksj,1,6) as yf, sum(hkje) as hkje 
    from t_htxx_hkxx  
    group by zhth, substr(hksj,1,6)
    ) a