比如我现在有一张表table,然后里面有个创建日期createDate,我现在要统计出createdate在昨天的总数,和今天的总数,如何操作?

解决方案 »

  1.   

    select count(条件) from table;
      

  2.   

    或者用linq  上面那个我也不知道对不对,,
      

  3.   

    select count(*) from xxx where createDate < @Max and createDate >= @Min@Max / @Min 参数设置为今天和昨天的时间范围就可以,
      

  4.   

    date 今天零点=now.date
    date 昨天零点=今天零点.adddays(-1)
    select * from table where createdate >= 昨天零点 and createdate < 今天零点
    select * from table where createdate >= 今天零点
      

  5.   


    //昨天
    select count(1) as yesterday from XX where datediff(d,ProgDate,getdate())=1 
    //今天
    select count(1) as today from XX where datediff(d,ProgDate,getdate())=0
      

  6.   

    其实这点儿事儿用SQL自己的时间函数就解决了select count(*) from table where createdate >= date(now());
    select count(*)  from table where createdate >= date_add(date(now()), interval -1 day) and createdate < date(now());
      

  7.   


    select convert(varchar(7),ViewDate,120) as month, COUNT(1) as NUM, from PageView
    group by convert(varchar(7),ViewDate,120) 
    order by month desc
    我是根据月份来取的  比如 3月10条 4月20条....但是我始终依稀觉得这样效率应该不高
      

  8.   

    谢谢各位,或许我没表述清楚,大家貌似都误会我的意思了,不过我已经解决了。
    昨天:
    string strYes=dateTime.Now.addDay(-1).Toshortdatetime();
    dateTime dtYes1=convert.todatetime(strYes+"0:00:00");
    dateTime dtYes2=convert.todatetime(strYes+"23:59:59");
    其实就这样,我想获得昨天零点到二十三点的时间。谢谢各位啦。