SQL怎么对某一列进行求和 并计数?一句sql语句可以写么
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL怎么对某一列进行求和 并计数?一句sql语句可以写么相关的知识,希望对你有一定的参考价值。
参考技术A 1.可以的;
2.
select
sum(列名),
Count(列名)
From
表
3.
你可以把问题描述的更加清楚点,才能更加有针对性的回答。 参考技术B select
sum(id4),count(*)
from
a_temp
;
可以一句SQL就直接查询得到列的和以及记录数。
该SQL中sum(id4)是列id4的总和,
count(*)是得到的数据总行数。本回答被提问者采纳
使用awk对某一列进行求和计算
使用awk对某一列进行求和计算
cat file.log
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
awk ‘{sum+=$4} END {print "total =",sum}‘ file.log
total = 3082.18
以上是关于SQL怎么对某一列进行求和 并计数?一句sql语句可以写么的主要内容,如果未能解决你的问题,请参考以下文章