sql2000表中有以下三行数据:name client count
penA zt 5
penB kl 6
penA es 7
penB sd 9要利用sql语句统计成
name count
penA 12
penB 15
请问如何写sql语句
penA zt 5
penB kl 6
penA es 7
penB sd 9要利用sql语句统计成
name count
penA 12
penB 15
请问如何写sql语句
group by [name]
order by [name]
select name, sum(count) from sql2000 group by name
select [name], sum([count]) from sql2000 group by name
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]
from tableName
group by [name]
order by 1
group by [name]
order by [name]
select cast([name] as varchar),[count]=sum([count]) from tb
group by [name]
order by [name]
select cast([name] as varchar),[count]=sum([count]) from tb
group by cast([name] as varchar)
order by cast([name] as varchar)
group by cast([name] as varchar(max))
order by cast([name] as varchar(max)) ,[count]
如果是text 类型,可以这样做
group by [name]
order by [name]
count 要加[]
这样就可以了,你试试!
from tableName
group by [name]
order by 1
select CONVERT(VARCHAR,[name]) AS [NAME],isnull(sum([count]),0) as 'count'
from tableName
group by [name]
order by 1
是TEXT型就转换成字符型
group by [name]
order by [name]