sql2000表中有以下三行数据:name    client    count 
penA       zt        5
penB       kl        6
penA       es        7
penB       sd        9要利用sql语句统计成
name    count
penA      12
penB      15
请问如何写sql语句

解决方案 »

  1.   

    select [name], sum([count]) from 表 group by  name,count
      

  2.   

    select [name],[count]=sum([count]) from tb 
    group by [name] 
    order by [name]
      

  3.   

    name和count都是SQL SERVER的保留字或关键字,不建议作为字段或对象名称,用的时候要在两边加[]
      

  4.   

    select [name], sum([count]) from TB group by  name,count
      

  5.   


    select name, sum(count) from sql2000 group by  name
      

  6.   

    修改
    select [name], sum([count]) from sql2000 group by  name
      

  7.   

    select [name], sum([count]) from 表 group by  name
      

  8.   

    SELECT[name], SUM([count]) AS [COUNT] FROM TABLE GROUP BY  [name]
      

  9.   

    select [name], sum([count]) from 表 group by  name忘了在前面有聚合函数是不用group by
      

  10.   

    select [name], sum([count]) from 表 group by  name
      

  11.   


    declare @tb table([name] varchar(10),client varchar(6),[count] int)
    insert into @tb select 'penA','zt',5
    union all select 'penB','kl',6
    union all select 'penA','es',7
    union all select 'penB','sd',9select [name],sum([count]) as [count] from @tb group by [name]
      

  12.   

    select [name], sum([count]) from [表] group by  [name]
      

  13.   

    select [name],sum([count]) as 'count'
    from tableName
    group by [name]
    order by 1
      

  14.   

    select [name],sum([count]) as [count] from tb group by [name] order by 1
      

  15.   

    select name,sum(count) as count from 表名 group by name
      

  16.   

    报错:不能比较或排序 text 数据类型,除非使用 IS NULL 或LIKE
      

  17.   

    name 是text类型,是否不能用order by? 执行时报错了:不能比较或排序 text 数据类型,除非使用 IS NULL 或LIKE 
      

  18.   

    name 是text类型,是否不能用order by? 执行时报错了: 不能比较或排序 text 数据类型,除非使用 IS NULL 或LIKE 
      

  19.   

    --试下这个select cast([name] as varchar),[count]=sum([count]) from tb 
    group by [name] 
    order by [name]
      

  20.   

    --试下这个
    select cast([name] as varchar),[count]=sum([count]) from tb 
    group by [name] 
    order by [name]
      

  21.   


    select cast([name] as varchar),[count]=sum([count]) from tb 
    group by cast([name] as varchar) 
    order by cast([name] as varchar)
      

  22.   

    select [name]=cast([name] as varchar(max)) ,[count]=sum([count]) from a 
    group by cast([name] as varchar(max)) 
    order by cast([name] as varchar(max)) ,[count]
    如果是text 类型,可以这样做
      

  23.   

    select [name],[count]=sum([count]) from tb 
    group by [name] 
    order by [name]
    count 要加[]
      

  24.   

    select name,count(*) from tb group by name;
    这样就可以了,你试试!
      

  25.   

    select [name],isnull(sum([count]),0) as 'count'
    from tableName
    group by [name]
    order by 1
      

  26.   


    select CONVERT(VARCHAR,[name]) AS [NAME],isnull(sum([count]),0) as 'count'
    from tableName
    group by [name]
    order by 1
    是TEXT型就转换成字符型
      

  27.   

    select name,sum(count) as count from table group by name 
      

  28.   

    select [name],[count]=sum([count]) from test 
    group by [name] 
    order by [name]