原始数据库为:
rq           bm      sl
2001-1-1     bm1      1
2001-1-2     bm2      2
2001-1-3     bm1      2
2001-1-10    bm1      2
2001-1-12    bm2      1
假设2号为周一,现在要求按周总结数据:
rq           bm      sl
2001-1-1     bm1      1 
2001-1-2     bm2      2      
2001-1-2     bm1      2
2001-1-9     bm1      2
2001-1-9     bm2      1
即把日期改为所在周的周一的日期.
数据大概有3000条,我用adotable逐条修改实现,但速度太慢,无法忍受。
求速度快的算法。

解决方案 »

  1.   

    没看明白,用update不行啊。??
      

  2.   

    思路1
    假设2001-1-2 为周一
    select 取余((rq-'2001-1-2')/7) as num from xxx
    num 等于 0的都是周一
      

  3.   

    update可以阿,可具体在么做阿?
      

  4.   

    ADOQuery.close;
    ADOQuery.Clear;
    ADOQuery.SQL.Add('Select * Table1');
    ADOQUery.Open;ADOQuery.close;
    ADOQery.SQL.Clear;
    ADOQery.SQL.Add('Updata Table1 where s1='+''''+'2'+'''');
    ADOQery.ExecSQL;
      

  5.   

    不是一样的吗?!
    Update Table1 Set f = DateAdd(dd, 0-DatePart(dw, f)+2, f) From Table1测试通过!!!不过要注意 你的SQL Server的FirstDate的值是多少!
    The weekday (dw) datepart returns a number that corresponds to the day of the week, for example: Sunday = 1, Saturday = 7. The number produced by the weekday datepart depends on the value set by SET DATEFIRST, which sets the first day of the week.
      

  6.   

    不好意思写错了:
    ADOQuery.close;
    ADOQuery.Clear;
    ADOQuery.SQL.Add('Select * Table1');
    ADOQUery.Open;ADOQuery.close;
    ADOQery.SQL.Clear;
    ADOQery.SQL.Add('Updata Table1 Set rq=' + ''''+ '日期'+ ''''+'where s1='+''''+'2'+'''');
    ADOQery.ExecSQL;
      

  7.   

    Update Table1 Set f = DateAdd(dd, 0-DatePart(dw, f)+2, f) From Table1
    这里各个参数都是什么?可以说清楚点么?
      

  8.   

    ADOQery.SQL.Add('Updata Table1 Set rq=' + ''''+ '日期'+ ''''+'where s1='+''''+'2'+'''');
    能讲解一下么?多谢。
      

  9.   

    基本同意guolinchao(潮)的方法。
      

  10.   

    dd,dw是什么意思?0-DatePart是什么意思?
    如果是按月和按年统计呢?