高分寻求日期问题的解决。

lzl09011 2002-10-23 04:31:57
原始数据库为:
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逐条修改实现,但速度太慢,无法忍受。
求速度快的算法。
...全文
51 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzl09011 2002-10-23
  • 打赏
  • 举报
回复
dd,dw是什么意思?0-DatePart是什么意思?
如果是按月和按年统计呢?
feiniao921 2002-10-23
  • 打赏
  • 举报
回复
基本同意guolinchao(潮)的方法。
lzl09011 2002-10-23
  • 打赏
  • 举报
回复
ADOQery.SQL.Add('Updata Table1 Set rq=' + ''''+ '日期'+ ''''+'where s1='+''''+'2'+'''');
能讲解一下么?多谢。
lzl09011 2002-10-23
  • 打赏
  • 举报
回复
Update Table1 Set f = DateAdd(dd, 0-DatePart(dw, f)+2, f) From Table1
这里各个参数都是什么?可以说清楚点么?
guolinchao 2002-10-23
  • 打赏
  • 举报
回复
不好意思写错了:
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;
日总是我哥 2002-10-23
  • 打赏
  • 举报
回复
不是一样的吗?!
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.
guolinchao 2002-10-23
  • 打赏
  • 举报
回复
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;
lzl09011 2002-10-23
  • 打赏
  • 举报
回复
update可以阿,可具体在么做阿?
zchz 2002-10-23
  • 打赏
  • 举报
回复
思路1
假设2001-1-2 为周一
select 取余((rq-'2001-1-2')/7) as num from xxx
num 等于 0的都是周一
hmily1688 2002-10-23
  • 打赏
  • 举报
回复
没看明白,用update不行啊。??
lzl09011 2002-10-23
  • 打赏
  • 举报
回复
我知道阿,但是怎样用呢?
各位大哥,帮帮我阿,就要交工了,我快急死了。
40Star 2002-10-23
  • 打赏
  • 举报
回复
SQL语句啊

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧