如何获取数据库中的总和和行数? [英] how to get sum and row count in database?
问题描述
我有一个包含以下数据的表
cnt_num .....点
1 .............. 500
1 .............. 1000
2 .............. 111
2 .............. 100
1 .............. 55
我需要将输出作为
cnt_num ..... total_points .... num_activity(row_count)
1 .................. 1555 ................................ 3
2 .................. 211 ................................. 2
我是数据库新手,一直在寻找解决方案.
任何帮助表示赞赏.在此先感谢
尝试如下查询.
选择 cnt_num,总和(点) as total_points,计数(cnt_num) 作为 num_activity 来自 TableName 组 按 cnt_num; pre>
RaisKazi是正确的.您可以使用该查询作为解决方案.
谢谢.
i have a table with following data
cnt_num .....points
1.............. 500
1.............. 1000
2.............. 111
2.............. 100
1.............. 55
i need to get output as
cnt_num .....total_points....num_activity (row_count)
1.................. 1555.......................3
2 ..................211........................2
i am new in database and have been searching allover for solution.
any help is appreciated. thanks in advance
Try as below Query.
select cnt_num, sum(points) as total_points, count(cnt_num) as num_activity from TableName Group By cnt_num;
RaisKazi is right. You can use that query for your solution.
Thanks.
这篇关于如何获取数据库中的总和和行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!