DataTable数据统计方法

调用方法:

public object Compute(string strExpression,string strFilter)

参数说明:

strExpression:要计算的表达式字符串,基本上类似于Sql Server中的统计表达式

strFilter:统计的过滤字符串,只有满足这个过滤条件的记录才会被统计

示例:

假设一个产品销售表table,描述某商场中各促销员销售的实际记录,包含字段为:姓名(Name)、性别(Sex,0为女,1为男)、生日(Birthday)、销售产品的代码(ProID)、销售的数量(Quantity)、销售价格(Price)。

1、统计所有性别为女的销售员的数量: table.Compute("Count(*)","Sex=0");

2、统计所有销售员中年龄大于20岁的: table.Compute("Count(*)","Birthday<'"+today);//today为今天的日期字符串

3、统计销售产品的平均价格: table.Compute("Aver(Price)","true");

4、统计产品代码为1的产品销售数量: table.Compute("Sum(Quantity)","ProID=1");

5、统计所有产品的销售总金额: 要统计总销售金额,由于table中不存在某项产品某个促销员销售的金额数据,但我们可以通过Quantity*Price来获得。比如: table.Compute("Sum(Quantity*Price)","true");

原文地址:https://www.cnblogs.com/sky-net/p/3526600.html