将数据库中列方向某个字段植相同的记录的其他字段相加求和的sql语句怎么写?
比如
time socer
1 10
1 22
1 33
2 34
2 11
把time为1的socer求和后
我想求和后成这样的格式
time total
1 65
应该怎么写??
比如
time socer
1 10
1 22
1 33
2 34
2 11
把time为1的socer求和后
我想求和后成这样的格式
time total
1 65
应该怎么写??
比如
time socer
1 10
1 22
1 33
2 34
2 11
把time为1的socer求和后
我想求和后成这样的格式(重新生成一张新表)
time total
1 65
应该怎么写??
上面的回复可以,利用分组就可以达到了
查询出指定 time 的socer 然后把查到的socer取和并且插入到一个临时表中,如果使用group得到的是表中所有的数据分组和,
select time,sum(socer) as tatal into #table from 表明 where time =字段 group by time