如果我按照产量汇总,然后加一列,这列按照汇总产量的大小
排上序号. 请问我应该怎么做呢???

解决方案 »

  1.   

    如果我按照产量汇总,然后加一列,这列按照汇总产量的大小
    排上序号. 请问我应该怎么做呢???
    -------------select id,sum(qty)as qty from t 
    group by id
    order by sum(qty)
      

  2.   

    order by 後可以接一些函數,排序
      

  3.   

    select 序號,sum(產量)as qty from t 
    group by 序號
    order by sum(產量)
      

  4.   

    其实是这样的,原来的表的内容docdate       matcode  digit  --列名 
    2007.05.01     num2       10
    2007.05.02     num2       20
    2007.05.03     num1       40
    2007.05.04     num1       50需要的效果是
    序号    matcode     产量
    1       num2        30
    2       num1         90
      

  5.   

    --如果不需要第一列Select matcode, SUM(digit) As 产量 From 表 Group By matcode
      

  6.   

    --如果需要第一列,需要借助臨時表Select ID = Identity(Int, 1, 1), matcode, SUM(digit) As 产量 Into #T From 表 Group By matcode
    Select * From #T
    Drop Table #T
      

  7.   

    select id=identity(int,1,1), matcode,sum(digit)as total into #t1 from #t group by matcode order by sum(digit)
      

  8.   

    id          matcode              total       
    ----------- -------------------- ----------- 
    1           num2                 30
    2           num1                 90(2 row(s) affected)