select a.month,b.Name,b.productname,a.Send,sum(a.send) as tsend,
a.Earning,sum(a.Earning) as tearning,a.Distribute,sum(a.Distribute) 
as tDistribute,a.Tax,sum(a.tax) as ttax,a.ComEarning,sum(a.ComEarning) 
as tComEarning,a.Memo from t_ManageInfor a , t_Custom b 
where a.IDCustom(+) = b.IDCustom  AND  a.Month  
between '10' and '12' group  by b.Name,b.productname,a.Send,
a.month,a.Earning,a.Distribute,a.Tax,a.ComEarning,a.Memo但如果加个order by a.month,不知为什么就分不了组我要先分组再排序,应该怎样写呢

解决方案 »

  1.   

    如果分组没问题,后面加order by 是没问题的
      

  2.   

    就是说我要根据公司名做分组,还要根据a.month做排序
    select a.month,b.Name,b.productname,a.Send,sum(a.send) as tsend,
    a.Earning,sum(a.Earning) as tearning,a.Distribute,sum(a.Distribute) 
    as tDistribute,a.Tax,sum(a.tax) as ttax,a.ComEarning,sum(a.ComEarning) 
    as tComEarning,a.Memo from t_ManageInfor a , t_Custom b 
    where a.IDCustom(+) = b.IDCustom  AND  a.Month  
    between '10' and '12' group  by b.Name,b.productname,a.Send,
    a.month,a.Earning,a.Distribute,a.Tax,a.ComEarning,a.Memo这样做是可以出的来的,样式是这样的
    公司名   月份    金额
             11        100
    A公司    10        120
             12        130
             12        140
    B公司    11        200
    10  400
    10        400
    C公司    11        300
             12        200但我还要根据a.month做排序
    用了
    select a.month,b.Name,b.productname,a.Send,sum(a.send) as tsend,
    a.Earning,sum(a.Earning) as tearning,a.Distribute,sum(a.Distribute) 
    as tDistribute,a.Tax,sum(a.tax) as ttax,a.ComEarning,sum(a.ComEarning) 
    as tComEarning,a.Memo from t_ManageInfor a , t_Custom b 
    where a.IDCustom(+) = b.IDCustom  AND  a.Month  
    between '10' and '12' group  by b.Name,b.productname,a.Send,
    a.month,a.Earning,a.Distribute,a.Tax,a.ComEarning,a.Memo order by a.month
    后,序是排出来了,可出来的记录却是这样的
                10        100
    A公司       10        120
                10        130
                11        140
    B公司       11        200
       11     400
       12        400
    C公司       12        300
                12        200我要这样的效果公司名   月份    金额
             10        100
    A公司    11        120
             12        130
             10        140
    B公司    11        200
    12  400
    10        400
    C公司    11        300
             12        200
      

  3.   

    order by 公司名 ,月份
      

  4.   

    可以使用RANK OVER + PARTITION GROUP的用法实现这种排名,相对来说语法简单性能快一些
      

  5.   

    想自定排序,可以加多一层select * from (select .... from .. where ... group by ...)
    order by ...