首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql语句:一个表中的数据统计

2012-01-07 
求一个sql语句:一个表中的数据统计比如一个表Table:col1col2a1a2c4c4e1用一个sql语句,返回一个集合:col1co

求一个sql语句:一个表中的数据统计
比如一个表Table:
col1       col2
a               1
a               2
c               4
c               4
e               1
用一个sql语句,返回一个集合:
col1         col2
a                 3
c                 8
e                 1
就是把第一列所有的数据求和。怎么写?

[解决办法]
select col1, col2=sum(col2) from tbName group by col1
[解决办法]
select col1,sum(col2) from table1 group by col1
[解决办法]
select col1,col2=sum(col2) from tablename group by col1
[解决办法]
select col1,sum(col2) col2
from table1
group by col1

热点排行