zoukankan      html  css  js  c++  java
  • inq to datatable group by 多列 实现

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication2
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("type", typeof (string));
                dt.Columns.Add("time", typeof (string));
                dt.Columns.Add("action", typeof (string));
                dt.Columns.Add("sum", typeof (string));
    
                dt.Rows.Add("A", "09:00:00", "举手", "5");
                dt.Rows.Add("A", "15:00:00", "扭腰", "3");
                dt.Rows.Add("A", "19:00:00", "扭腰", "3");
    
                dt.Rows.Add("B", "08:00:00", "抬脚", "2");
                dt.Rows.Add("B", "11:00:00", "举手", "2");
    
                dt.Rows.Add("C", "08:00:00", "扭脖子", "6");
                dt.Rows.Add("C", "09:00:00", "提臀", "5");
                var query = from t in dt.AsEnumerable()
                    group t by new
                    {
                        t1 = t.Field<string>("type")
                        //,t2 = t.Field<DateTime>("arrivalTime")多个条件
                    }
                    into m
                    select new
                    {
                        time = string.Join("---", m.Select(n => n.Field<string>("time")).ToArray()),
                        type = m.Key.t1,
                        action = string.Join("/", m.Select(n => n.Field<string>("action")).ToArray()),
                        rowcount = m.Count()
                    };
                  var sss = query.ToList();
    
         
            }
        }
    }

    参考http://blog.csdn.net/q107770540/article/details/6086577

  • 相关阅读:
    1211.zuoye
    hw.python 鹿宏扬
    1206 python 鹿宏扬
    linux基础笔记
    Python20181204
    python1819 鹿宏扬 linux基础笔记
    [Kotlin]Spring Boot 使用thinJar打包找不到manifest问题
    Spring Boot设置默认返回UTF-8
    Go实现上传下载功能
    Flutter(二)Form Validating(表单验证)
  • 原文地址:https://www.cnblogs.com/y112102/p/6206249.html
Copyright © 2011-2022 走看看