zoukankan      html  css  js  c++  java
  • linq 日期分组统计

     #region
            string Condition(DateTime date, string type)
            {
                if (date == null)
                {
                    date = DateTime.MinValue;
                }

                if (type == "day")
                {
                    return date.ToString("yyyy-M-d");
                }
                else if (type == "month")
                {
                    return date.ToString("yyyy-M");
                }
                return date.Year.ToString();
            }
            public void xx()
            {
                List<DateTime> datelist = new List<DateTime>();
                var today = DateTime.Now.Date;
                for (var i = 0; i < 7;i++ )
                {
                    datelist.Add(today.AddDays(-i));
                }

                var oderlist = this.Find().AsEnumerable();
                var result = from m in datelist
                             join n in oderlist on Condition(m, "day") equals Condition(n.create_time, "day") into c
                             from cc in c.DefaultIfEmpty()
                             group cc by Condition(m, "day") into g
                             select new { g.Key, Total = (g.FirstOrDefault()==null?0:g.Count())};

                var ccc = result.ToList();

            }
            #endregion
  • 相关阅读:
    Docker之概述
    redis命令
    spring mvc(1) 为什么要使用mvc
    学习到的
    HttpWebRequest简单使用
    推手总结
    react 生命周期
    利用反射对应数据库字段
    扩展方法
    发送请求并返回
  • 原文地址:https://www.cnblogs.com/waitingfor/p/4321452.html
Copyright © 2011-2022 走看看