select a.STAT_TIME,
       b.F_CITY_CODE as CITY_CODE,
       sum(a.pay_fee) as AMOUNT,
       d.fee as BANK_AMOUNT
  from brpt_bf_n_8035_temp_t a,
       om_area_t b,
       (select to_char(op_day, 'yyyymmdd'), city_code, sum(t.fee3_crm) fee
          from rpt_user.brpt_reserve_deposit_month_t@bill2crm t, om_area_t c
         where c.F_CITY_CODE = t.city_code
           and c.f_area_level = '3'
           and t.op_day >= to_date('2014101', 'yyyymmdd')
           AND t.op_day < to_date('20141002', 'yyyymmdd')
         group by op_day, city_code) d
 where a.city_code = b.f_area_code
   and b.F_CITY_CODE = d.city_code
   and b.f_area_level = '3'
   and a.STAT_TIME = '20141001'
 group by STAT_TIME, b.F_CITY_CODE, d.fee
 order by b.F_CITY_CODE;

解决方案 »

  1.   

    如果查询语句中存在group子句
    则select子句中只能是group by 子句中的字段,或是能通过这些字段生成的公式,或是组函数,或是常数
    d.fee as BANK_AMOUNT在group子句中没有,因此在这里写会报错可以改为max(d.fee) as BANK_AMOUNT
      

  2.   

    d.fee 不在组合 group by STAT_TIME, ( b.F_CITY_CODE)  范围内的,系统无法给出查询结果~ 
      

  3.   

    以下两句的字段列表要一致,除非使用了 max() , min() , avg() , count() 等函数。a.STAT_TIME,
    b.F_CITY_CODE as CITY_CODE,
    sum(a.pay_fee)as AMOUNT,
    d.fee as BANK_AMOUNT
    group by STAT_TIME, ( b.F_CITY_CODE) 
      

  4.   

    没有用聚合函数的列,应该出现在GROUP BY 子句中
      

  5.   

    还有一种可能是,它输出的字段中只有日期和城市是个key,paid fee 显示个收到的总和,而 fee 却显示明细,用 OLAP Window 函数能做到,从它的表结构猜想  a 和 b 应该是个静态数据(例如外出出报表的机构层次范围),不会有重复记录:
    select a.STAT_TIME,
           b.F_CITY_CODE as CITY_CODE,
           sum(a.pay_fee) over (partition by  STAT_TIME, b.F_CITY_CODE) as AMOUNT,
           d.fee as BANK_AMOUNT
      from brpt_bf_n_8035_temp_t a,
           om_area_t b,
           (select to_char(op_day, 'yyyymmdd'), city_code, sum(t.fee3_crm) fee
              from rpt_user.brpt_reserve_deposit_month_t@bill2crm t, om_area_t c
             where c.F_CITY_CODE = t.city_code
               and c.f_area_level = '3'
               and t.op_day >= to_date('2014101', 'yyyymmdd')
               AND t.op_day < to_date('20141002', 'yyyymmdd')
             group by op_day, city_code) d
     where a.city_code = b.f_area_code
       and b.F_CITY_CODE = d.city_code
       and b.f_area_level = '3'
       and a.STAT_TIME = '20141001'
     -- 不需要 group by 了 ,我们出的是明细。
     order by b.F_CITY_CODE;
      

  6.   

    又看了它的条件,看上去 d 里面的条件与最外面的条件似乎是一致的,因此不需要 OLAP Window 函数,还是把 d.fee 放到 group by 后面就好了,那 >= to_date 里面应该是 20141001 吧?只算一天就只有一天记录。
      

  7.   

    提示很清楚,group by 的内容不正确,你查询的时候,只允许查询出group by的列以及 其它列用函数计算出的唯一值