获取最近30天数据
public void Get30DaysClickData(HttpContext context) { List<DayClickModel> dayList = Init30DaysList(); string sql = "SELECT CONVERT(VARCHAR(10),CreateTime,120) AS curDay,COUNT(1) AS totalCount FROM Shop_LaiLu_Logs where AccountId=" + accountId + " and DATEDIFF(dd,CreateTime,GETDATE())<=30 GROUP BY CONVERT(VARCHAR(10),CreateTime,120) ORDER BY curDay desc"; DataSet ds = DB.DataSet(baiduConnStr, sql); if (DataHelper.ExistsDataSet(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { string curDay = dr["curDay"].ToString(); DayClickModel dayModel = dayList.Where(item => item.day == curDay).FirstOrDefault(); if (dayModel != null) { dayModel.value = DataConvert.ToInt(dr["totalCount"]); } } } WriteString(context, true, "", dayList); } public List<DayClickModel> Init30DaysList() { DateTime dt = DateTime.Now; List<DayClickModel> list = new List<DayClickModel>(); for (int i = 0; i < 30; i++) { string curDay = dt.AddDays(i - 29).ToString("yyyy-MM-dd"); DayClickModel dayModel = new DayClickModel { day = curDay, value = 0 }; list.Add(dayModel); } return list; }