• Datatable 列查询,统计值


    Column 列查询,如下:

                var dt = CommonUtil.ToDataTable(dataJson);
                //判断是否有当前日期数据
                var systemDateTime = new CommonProperty().SystemDateTime;
                DataRow[] drArray = dt.Select(string.Format("COL_ActDate>='{0}' and COL_ActDate<'{1}'",
                    systemDateTime.Date.ToString("yyyy-MM-dd HH:mm:ss"),
                    systemDateTime.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")));
                if (!drArray.Any()) throw new Exception("数据中没有当前日期数据无法保存");
    
                var dicUpdate=new Dictionary<decimal, decimal?>();
                var addList = new List<CraftParaActEntity>();
                foreach (var column in dt.Columns)
                {
                    string strColumn = column.ToString();
                    if (!strColumn.Contains("COL_Value_")) continue;
                    string strColumnId = string.Format("COL_CraftParaActId_{0}", strColumn.Replace("COL_Value_", ""));                                     
             DataRow[] drIdArray = dt.Select(string.Format("{0} is not null", strColumnId));               
              decimal columnId = decimal.Parse(drIdArray[0][strColumnId].ToString());                 
              decimal craftParaId = CraftParaActDALService.QuerySingleCraftParaAct(columnId).CraftParaId; }

     计算列中的统计值,使用聚合函数,此列应是int,decimal可计算的数据类型,如下:

                    var maxValue = dt.Compute(string.Format("max({0})", strColumn), "true");
                    var minValue = dt.Compute(string.Format("min({0})", strColumn), "true");
                    var avgValue = dt.Compute(string.Format("avg({0})", strColumn), "true");
  • 相关阅读:
    es6 数组的扩展
    面向对象的7大原则及其实例
    flex 布局
    一、创建vue
    箭头函数
    destructuring
    spreed&rest
    变量新声明之let、const
    jQuery之遍历索引相关方法
    jQuery之位置坐标图形相关方法
  • 原文地址:https://www.cnblogs.com/yisheng/p/6182930.html
Copyright © 2020-2023  润新知