select uid, date,sum(num) as num from table where date >=@StartDate And date < @EndDate group by uid,date order by uid,dateList<Entity> list;//假定读取出来的数据集 DateTime startDay = new DateTime(Now.Year,Now.Month,1);//对应sql的@StartDate DateTime endDay = firstDay.AddMonth(1);//对应sql的@EndDate //读取填充list int monthDays = (endDay - firstDay).Days; var query = from e in list group e by e.Uid into g select g;foreach(var g in query) { for(int i=1;i<=monthDays;i++) { DateTime compareDay = new DateTime(Now.Year,Now.Month,i); Entity entity = list.Where(e=>e.Date==compareDay).FirstOrDefault(); if(entity==null) { list.Add(new Entity(){Uid=g.Key,Date=compareDay,Num=0}); } } } //补充:如果某些人一个月内都没记录,这样是查不到的,所以如果又必须要,还需要与员工表作对比 //排序
where date >=@StartDate And date < @EndDate
group by uid,date
order by uid,dateList<Entity> list;//假定读取出来的数据集
DateTime startDay = new DateTime(Now.Year,Now.Month,1);//对应sql的@StartDate
DateTime endDay = firstDay.AddMonth(1);//对应sql的@EndDate
//读取填充list
int monthDays = (endDay - firstDay).Days;
var query = from e in list
group e by e.Uid into g
select g;foreach(var g in query)
{
for(int i=1;i<=monthDays;i++)
{
DateTime compareDay = new DateTime(Now.Year,Now.Month,i);
Entity entity = list.Where(e=>e.Date==compareDay).FirstOrDefault();
if(entity==null)
{
list.Add(new Entity(){Uid=g.Key,Date=compareDay,Num=0});
}
}
}
//补充:如果某些人一个月内都没记录,这样是查不到的,所以如果又必须要,还需要与员工表作对比
//排序
foreach(var g in query)
{
if(g.Value.Count<monthDays))
{
for(int i=1;i<=monthDays;i++)
{}
}这一段
第一步,一次性取出所有该月该工人录入的数据,方法应该不用说了,假如结果集是List<Product> products
第二步,循环显示每天的记录,象这样:
//先获取该月总天数
var days=DateTime.DaysInMonth(2013,10);
for(int i=1;i<=days;i++){
//i号的件数就是 products.Where(p=>p.日期.Day==i).Sum(p=>p.件数);
}
=================================================================
ASP.NET MVC免费分页控件MvcPager 2.0版发布,功能更强大,欢迎使用:
http://www.webdiyer.com/mvcpager/