Linq-分组统计
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication2
{
public class Plan
{
public string ProjectInfoId
{
get;
set;
} public string CommandInfoId
{
get;
set;
} public int value
{
get;
set;
}
} class Program
{
static void Main(string[] args)
{
List<Plan> listPlan = new List<Plan>() {
new Plan{ProjectInfoId="", CommandInfoId="", value=},
new Plan{ProjectInfoId="", CommandInfoId="", value=},
new Plan{ProjectInfoId="", CommandInfoId="", value=},
new Plan{ProjectInfoId="", CommandInfoId="", value=},
new Plan{ProjectInfoId="", CommandInfoId="", value=},
new Plan{ProjectInfoId="", CommandInfoId="", value=},
}; var PlanGroups =
from p in listPlan
group p by
new
{
p.ProjectInfoId,
p.CommandInfoId }
into g
let condition = g.Sum<Plan>(t => t.value)
where condition >
select new
{
g.Key,
NumProducts = condition
}; foreach (var group in PlanGroups)
{
Console.WriteLine(string.Format("{0},{1}:{2}", group.Key.ProjectInfoId.ToString(), group.Key.CommandInfoId.ToString(), group.NumProducts));
}
}
}
}
Linq-分组统计的更多相关文章
- Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等)
Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等) 子查询 描述:查询订单数超过5的顾客信息 查询句法: var 子查询 = from c i ...
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
2013-9-15 1. CustomValidator验证控件验证用户输入的字符长度 在实际的开发中通常会遇到验证用户输入的字符长度的问题,通常的情况下,可以写一个js的脚本或者函数,在ASP ...
- C# Linq及Lamda表达式实战应用之 GroupBy 分组统计
在项目中做统计图表的时候,需要对查询出来的列表数据进行分组统计,首先想到的是避免频繁去操作数据库可以使用 Linq eg: //例如对列表中的Cu元素进行按年GroupBy分组统计 //包含年份,平均 ...
- DataTable、List使用groupby进行分组和分组统计;List、DataTable查询筛选方法
DataTable分组统计: .用两层循环计算,前提条件是数据已经按分组的列排好序的. DataTable dt = new DataTable(); dt.Columns.AddRange(new ...
- Linq分组功能
Linq在集合操作上很方便,很多语法都借鉴自sql,但linq的分组却与sql有一定的区别,故整理发布如下. 1. Linq分组 分组后以Key属性访问分组键值. 每一组为一个IEnumberAbl ...
- 【.Net】 大文件可使用的文本分组统计工具(附带源码,原创)
本工具可实现的效果: 1.读取大文件(大于1GB) 2.根据分隔符分割后的列分组 3.速度快. 4.处理过程中,可以随时停止处理,操作不卡死. 5.有对当前内存的实时监测,避免过多占用内存,影响系统运 ...
- Dev用于界面按选中列进行分组统计数据源(实用技巧)
如果有用U8的可以明白这个功能就是模仿他的统计功能.我不过是把他造成通用的与适应于DEV的. (效率为6000条数据分组统计时间为3秒左右分组列过多5秒.1000条以下0.几秒,500条下0.00几秒 ...
- ORACLE的分组统计之ROLLUP(一)
Oracle 9i以后,扩展了group by 的功能,能够满足大部分多维数据的分析统计功能,主要表现: 1. rollup,cube,grouping sets 扩展group by字句提供了丰富的 ...
- XtraGrid使用心得(折叠式主细档、分组统计)
XtraGrid的关键类就是:GridControl和GridView.GridControl本身不显示数据,数据都是显示在GridView/CardView/XXXXView中.GridContro ...
- Oracle按不同时间分组统计
Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...
随机推荐
- Data import/export of Netezza using external table
Introduction External table is a special table in Netezza system, which could be used to import/exp ...
- Mac OS X的空间去哪儿了
记得有事儿没事儿看下,/cores/目录的大小. cores目录是存放程序dump的数据,对于绝大部分人时是没有用的.可以删除.如果遇到坑爹的程序,一直生成dump文件,硬盘瞬间就爆满了. 典型:An ...
- Android笔记:如何在Fragment里使用findViewById()方法?
在Activity中,可以直接用findViewById(int id),通过xml的id来找到对应的View. 查找官方的api,具体如下: https://developer.android.go ...
- .NET HttpClient扩展
/// <summary> /// HttpClient扩展类 /// </summary> public static class HttpClientExtensions ...
- js 事件绑定
事件绑定的方式 1. DOM 元素行内绑定 <div onclick="alert(1)"></div> 2. js on+eventType do ...
- 用 python实现简单EXCEL数据统计
任务: 用python时间简单的统计任务-统计男性和女性分别有多少人. 用到的物料:xlrd 它的作用-读取excel表数据 代码: import xlrd workbook = xlrd.open_ ...
- sublime插件 cssComb实现css自动排序及格式化
cssComb是一个实现css代码自动排序,当然顺便也实现了代码的格式化 安装: 首先需要打开sublime搜索安装csscomb插件(前提是已经安装了sublime的package control) ...
- RancherOS Hyper-V 安装
RancherOS Hyper-V 安装, Install to disk 打开 Hyper-V 管理界器, 新建虚拟机 输入名称和存储位置 选择一代 最低 1024M 配置网络 创建虚拟磁盘 设置启 ...
- SQL Server 2008 r2 输入SQL语句不能自动提示的解决办法
先利用“配置工具-SQL Server 配置管理器”关闭所有MSSQLSERVER服务,利用SQL Server Installation Center,进入Maintenance,选择Repair, ...
- ChartServices Dev图形封装
.工具类ChartServices using System; using System.Data; using System.Drawing; using DevExpress.XtraCharts ...