SQL> SELECT   COUNT (r.rdj_grbh) rs, COUNT (DISTINCT f.bih_id) fs,
  2           SUM (f.fcz_czmj) OVER (PARTITION BY f.bih_id) mj,
  3           SUM (f.fcz_czjs) OVER (PARTITION BY f.bih_id) js
  4      FROM sjcj_rydjbxx r, sjcj_fwdjbxx f
  5  group by r.rzf_xzdxzqh;
         SUM (f.fcz_czmj) OVER (PARTITION BY f.bih_id) mj,
              *
第 2 行出现错误:
ORA-00979: 不是 GROUP BY 表达式
sjcj_rydjbxx r 中r.rdj_grbh 与sjcj_fwdjbxx  f.bih_id 是一对多的关系求教!

解决方案 »

  1.   

    --这样就可以了吧?
    SELECT   COUNT (r.rdj_grbh) rs, COUNT (DISTINCT f.bih_id) fs,
             SUM (f.fcz_czmj) OVER (PARTITION BY f.bih_id) mj,
             SUM (f.fcz_czjs) OVER (PARTITION BY f.bih_id) js
    FROM sjcj_rydjbxx r, sjcj_fwdjbxx f
      

  2.   

    楼主是对分析函数的使用不太了解.分析函数是对select语句查询出的结果进行再处理的时候使用的.
    所以分析函数不可能出现在用于得到select结果的group by 后面.
    比如select empno,sum(sal)over(partition by deptno) from emp;
    这个语句实际上相当于先执行select * from emp;
    然后再对查询结果使用分析函数按deptno分组计算sal和,然后得到结果.
      

  3.   

    Use OVER analytic_clause to indicate that the function operates on a query result set. That is, it is computed after the FROM, WHERE, GROUP BY, and HAVING clauses. You can specify analytic functions with this clause in the select list or ORDER BY clause. To filter the results of a query based on an analytic function, nest these functions within the parent query, and then filter the results of the nested subquery.
      

  4.   


    --有分析函数就可以了  去看看相关的文档
    SQL> SELECT   COUNT (r.rdj_grbh) rs, COUNT (DISTINCT f.bih_id) fs,
      2           SUM (f.fcz_czmj) OVER (PARTITION BY f.bih_id) mj,
      3           SUM (f.fcz_czjs) OVER (PARTITION BY f.bih_id) js
      4      FROM sjcj_rydjbxx r, sjcj_fwdjbxx f
      

  5.   


    --有分析函数就可以了  去看看相关的文档
    SQL> SELECT   COUNT (r.rdj_grbh) rs, COUNT (DISTINCT f.bih_id) fs,
      2           SUM (f.fcz_czmj) OVER (PARTITION BY f.bih_id) mj,
      3           SUM (f.fcz_czjs) OVER (PARTITION BY f.bih_id) js
      4      FROM sjcj_rydjbxx r, sjcj_fwdjbxx f