3.58 msum - Sum of Column

Aggregate the sum of values in the records at the specified field defined at f= parameter for records with the same key value defined at k=.

Format

msum f= [k=] [-n] [i=] [o=] [tmpPath=] [-nfn] [-nfno] [-x] [-q] [precision=] [--help] [--version]

Parameters

k=

Specify list of field name(s) (multiple fields can be specified) as aggregate unit.

f=

Aggregate the values specified at the field(s) (multiple items can be specified). Records with NULL values are ignored.

-n

If NULL exist in the field defined at f=, the result will return NULL.

Example

Example 1: Basic Example

Calculate the total value of "quantity" and "amount" for each "customer". Save the output with field names "total quantity" and "total amount".

$ more dat1.csv
customer,quantity,amount
A,1,10
A,2,20
B,1,15
B,3,10
B,1,20
$ msum k=customer f=quantity:quantitySum,amount:amountSum i=dat1.csv o=rsl1.csv
#END# kgsum f=quantity:quantitySum,amount:amountSum i=dat1.csv k=customer o=rsl1.csv
$ more rsl1.csv
customer%0,quantitySum,amountSum
A,3,30
B,5,45

Related Commands

mhashsum : Compute sum without sorting by aggregate key in advance.

mavg : Compute average.

mstats : Compute a variety of statistics.