DataTable Group By或运算 Linq Aggregate的使用
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(System.String));
dt.Columns.Add("Value", typeof(System.Int32)); dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", ); dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", ); var query = from t in dt.AsEnumerable()
group t by new { Name = t.Field<string>("Name") } into m
select new
{
Name = m.Key.Name,
Sum = m.Sum(n => n.Field<int>("Value")),
CustomerValue = m.Aggregate(, (d, n) =>
{
return d | n.Field<int>("Value");
})
}; query.ToList().ForEach(p =>
{
Console.WriteLine($"Name:{p.Name}\tSum:{p.Sum}\tCustomerValue:{p.CustomerValue}");
});
Console.ReadKey();
}
}
DataTable Group By或运算 Linq Aggregate的使用的更多相关文章
- C# Datatable group by 查询
操作Datatable group by 查询 //获取统计图形数据 var dicleft = new Dictionary<string, DataTable>(); ].AsEn ...
- Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5
linq to sql 的时候,有时候需要用到 先group 然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...
- Linq DataTable Group By 分组显示人员明细
实现功能: 多个字段分组源码样例: 原始数据: 分组后的输出结果: 源代码: public static void PrintPersons() { //准备数据 DataTable dt ...
- inq to datatable group by 多列 实现
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.T ...
- datatable group by
对datatable 里面的数据按某一特定的栏位进行分组并且按照某一规则 var query = from t in rate.AsEnumerable() group t by new { t1 ...
- DataTable的筛选,过滤后绑定数据源的两种方法(DataTable的select和使用linq返回List集合)
一般数据处理使用DataTable的情况会很多,而我们很多时候会对得到的DataTable的数据进行筛选后绑定到Combobox.GridView.Repeat等控件中,现在分享一下两种DataTab ...
- 一条结合where、group、orderby的linq语法
DataTable dt = (from x in dsResult.Tables[0].AsEnumerable() where DataTrans.CBoolean(x["IsCheck ...
- Linq: Aggregate
Aggregate累加器 今天看东西的时候看见这么个扩展方法Aggregate(累加器)很是陌生,于是乎查了查,随手记录一下. 直接看一个最简答的版本,其他版本基本没什么区别,需要的时候可看一下 pu ...
- 20180519001 - DataTable Group by功能参考
DataSet6 = DataSet1.Copy(); DataRow[] dr = DataSet6.Tables[0].Select(" 完工状态 = '完工异常' "); D ...
随机推荐
- ubuntu 12.10 apt-get 源
更改apt-get源配置文件/etc/apt/sources.list 用一下内容替换掉 deb http://mirrors.163.com/ubuntu/ precise main restric ...
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- Mysql 变量讲解
set语句的学习: 使用select定义用户变量的实践将如下语句改成select的形式: set @VAR=(select sum(amount) from penalties);我的修改: sele ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- opencv中彩色图转换成灰度图rgb2gray
imread函数读入图像: 只需要将imread的第二个参数置为0即可. Mat imread(const string& filename, intflags=1 ); 第一个参数是载入图片 ...
- ios --也是在B页面的生命周期设置如下代码。方法一是直接关闭和激活侧滑手势,方法二则是B遵循协议UIGestureRecognizerDelegate,设置侧滑交互代理,重写手势方法。
@property (weak, nonatomic) id<UIGestureRecognizerDelegate> restoreInteractivePopGestureDelega ...
- python中json操作
1.写操作.json文件dumps().dump()函数 d = { 'zll': { 'addr': '北京', 'age': 28 }, 'ljj': { 'addr': '北京', 'age': ...
- [Spring Data MongoDB]学习笔记--牛逼的MongoTemplate
MongoTemplate是数据库和代码之间的接口,对数据库的操作都在它里面. 注:MongoTemplate是线程安全的. MongoTemplate实现了interface MongoOperat ...
- 【BZOJ3994】[SDOI2015]约数个数和 莫比乌斯反演
[BZOJ3994][SDOI2015]约数个数和 Description 设d(x)为x的约数个数,给定N.M,求 Input 输入文件包含多组测试数据. 第一行,一个整数T,表示测试数据的组 ...
- Cocos2d-x Lua中使用标签
游戏场景中的文字包括了静态文字和动态文字.静态文字如下图所示游戏场景中①号文字“COCOS2DX”,动态文字如图4-1所示游戏场景中的②号文字“Hello World”.静态文字一般是由美工使用Pho ...