有一个表a
select code,name,sum(count) as total group by code,name
问题是我要对汇总的total按由大到小排列:
用order by total 吗?

解决方案 »

  1.   

    order by total DESC //降序
    order by total ASC  //升序
      

  2.   

    试一试
    select code,name,sum(count) as total from table group by code,name order by sum(count) desc
    sql server2000 下通过。
      

  3.   

    同上order by 列名 desc/asc
      

  4.   

    order by 列名 DESC //降序
    order by 列名 ASC  //升序
      

  5.   

    select code,name,sum(count) as total 
    from a 
    group by code,name
    order by total desc
    這樣一定可以的,sql問題,本人願意和大家共免
      

  6.   

    order by 列名 DESC //降序
    order by 列名 ASC  //升序
      

  7.   

    order by total DESC //降序
    order by total ASC  //升序
      

  8.   

    select code,name,sum(count) as total  order by total (DESC或ASC) group by code,name 
      

  9.   

    select distinct a.dj,a.jxjyjb from examinee,(select distinct sum(count) as dj,jxjyjb from examinee group by jxjyjb) as a where a.jxjyjb=examinee.jxjyjb order by dj desc
      

  10.   

    你的问题应该是分组排序的意思
    例:
    code name count
    ==============
    1   a     23
    1   a     10
    2   b     4
    2   b     7
    ………………统计要求应该是:
    (1-a):23+10=33
    (2-b):4+7=11下面语句可以实现
    select code, sum(count) as totalfrom tb1
    where …
    group by code
    order by total