数据表名:HonorID  score       time
1     1         2009-11-5 17:30
2     1         2009-11-15 15:35   
3     -1        2009-11-16 16:30 
4     0         2009-10-16 16:30 需要统计近一周、,近一个月、近三个月,得分为1,-1,0的数量请问用C#如何实现啊,谢谢!
希望各位可详细指点一下啊..

解决方案 »

  1.   

    用SQL可以很轻松解决的,涉及select count(*) where where diff(day,time,getdate())<=7(此处一个月就是30,三个月就是90) 
      

  2.   

    补充一下,条件里还应加上and score=1(-1,0)
      

  3.   


    declare @t table( [id] int , score int , [time] datetime)insert into @t values(1  ,  1    ,    '2009-11-5 17:30'   )
    insert into @t values(2  ,  1    ,    '2009-11-15 15:35'  )
    insert into @t values(3  ,  -1   ,     '2009-11-16 16:30' )
    insert into @t values(4  ,  0    ,    '2009-10-16 16:30'  )select score , count([id]) as num ,'周' as type   from @t   where DATEDIFF(day,time,getdate()) <=7 
    group by score 
    union all 
    select score , count([id]) as num ,'月' as type   from @t   where DATEDIFF(day,time,getdate()) <=30 
    group by score 
    union all 
    select score , count([id]) as num ,'三个月' as type   from @t   where DATEDIFF(day,time,getdate()) <=90 
    group by score 
      

  4.   

    其他的自己修改一下!            //统计近一周
                int i=0;
                int j = 0;
                int m = 0;
                foreach (DataRow d in dt.Rows)
                {
                    if (DateTime.Compare(DateTime.Parse(d[3].ToString()), DateTime.Now) <= 7)
                    {
                        switch (d[1].ToString())
                        {
                            case "1":
                                i++;
                                break;
                            case "0":
                                j++;
                                break;
                            case "-1":
                                m++;
                                break;
                        }
                    }            }
                Console.WriteLine("近一周内:1次数"+i.ToString()+"\n"+"0次数"+j.ToString()+"\n"+"-1次数"+i.ToString());
      

  5.   

    TO xinke_li:System.Data.SqlClient.SqlException: 'diff' 不是可以识别的 内置函数名称。
      

  6.   

    可能之前说得有点简单:
    数据表名:Honor ID  score      time                  sales     buyer
    1    1        2009-11-5 17:30        redhcy     hcy
    2    1        2009-11-15 15:35       redhcy     bluehcy
    33    -1        2009-11-16 16:30      hcy        wm
    40    0        2009-10-16 16:30       hcy        wm
    ..............score表示用户的评分  time表示评价时间  sales表示卖家   buyer表示买家
    表中的行数是不断增加的,有用户评分,就增加一行数据。需要统计并显示在aspx页面上:卖家=lbluser.text,得分为1,一周内的评价数;
    卖家=lbluser.text,得分为-1,一周内的评价数;
    卖家=lbluser.text,得分为0,一周内的评价数;
    卖家=lbluser.text,得分为1,一个月内的评价数;
    卖家=lbluser.text,得分为-1,一个月内的评价数;
    卖家=lbluser.text,得分为0,一个月内的评价数;
    卖家=lbluser.text,得分为1,六个月内的评价数;
    卖家=lbluser.text,得分为-1,六个月内的评价数;   
    卖家=lbluser.text,得分为0,六个月内的评价数;买家=lbluser.text,得分为1,一周内的评价数;
    买家=lbluser.text,得分为-1,一周内的评价数;
    买家=lbluser.text,得分为0,一周内的评价数;
    买家=lbluser.text,得分为1,一个月内的评价数;
    买家=lbluser.text,得分为-1,一个月内的评价数;
    买家=lbluser.text,得分为0,一个月内的评价数;
    买家=lbluser.text,得分为1,六个月内的评价数;
    买家=lbluser.text,得分为-1,六个月内的评价数;   
    买家=lbluser.text,得分为0,六个月内的评价数;
    如何实现比较便捷,求高人详细指点啊!越详细越好..