表结构和数据如下:
ID type count
1 a 10
2 b 20
3 c 30
4 d 5
5 b 13
6 c 2
7 b 7
请问如果SQL语句按"type"求出count总数ID type count
1 a 10
2 b 40
3 c 32
4 d 5
多谢!

解决方案 »

  1.   

    select Type,Sum(Count) from table1 group by Type
      

  2.   

    select IDENTITY(int, 1,1) as ID, type, sum([count]) as [count] into #temp
    from 表
    group by type 
    order by type
    select * from #temp
    /////////////////////
    使用完后要
    drop table #temp
      

  3.   

    yhg_zl(原野) is right, 
    select Type, Sum(Count) as perCount from table1 group by Type order by Type
    add an order func...
    取:ADOQuery.FieldByName('perCount').asString is OK
      

  4.   

    select min(id), Type, Sum(Count) from table1 group by Type
      

  5.   

    select Type,Sum(Count) from table1 group by Type
      

  6.   

    用一个表可能不行吧,弄个中间表select type,sum(count) as count into temptable from table group by typeselect table.id,temptable.type,temptable.count from temptable,table where temptable.type = table.type
      

  7.   

    1:
    select min(id) as id, Type, Sum(Count) as count from table1 group by Type
    2:
    select identity(int,1,1) as id,* into #tmp
    from 
    (
    select Type,Sum(Count) from table1 group by Type
    ) aa
    select * from #tmp 
    drop table #tmp
      

  8.   

    回复人: hthunter(核桃)(见过mm了) ( ) 信誉:100  2004-01-13 12:46:00  得分:0 
     
      select min(id), Type, Sum(Count) from table1 group by Type********************************
    这个最可取