你根据 substr(N_community,1,level*2) 进行group by 
必须 这样用,否则,出现一对多的情况。

解决方案 »

  1.   

    那是否可以AS做别名select substr(N_community,1,level*2) as N_community这样的呢?
      

  2.   

    如果是做别名select substr(N_community,1,level*2) as N_community ,那么排序应该用group by N_community。
      

  3.   

    可我就是想用substr(N_community,1,level*2)分组, N_community 作为显示字段,不能作到吗?
      

  4.   

    你看看增加一列行不行,代码如下:
    select N_community,C_stat_time,sum(N_up) as N_up,substr(N_community,1,level*2) as Column1,
    from T_retire_change_collect where N_state=1 
    group by Column1,C_stat_time 
    order by C_stat_time desc,Column1
      

  5.   

    group by 函数就是这样的。
    比如对于aaa.aab,aac。前两个字符都是aa,如果你按aa分组,却又要显示,那是显示aaa,aab还是aac呢?
      

  6.   

    为什么一定要把substr放在group by中呢?这样不行啊
      

  7.   

    为什么不行呢?
    不是我要放啊,分组就是按SUBSTR后的结果分的啊
      

  8.   

    select max(N_community),C_stat_time,sum(N_up) as N_up
    from T_retire_change_collect where N_state=1 
    group by substr(N_community,1,level*2),C_stat_time 
    order by C_stat_time desc,N_community这样试试
      

  9.   

    执行不了,ORA-00923:FROM keyword not fount where expected楼上的是MM?