34,590
社区成员
发帖
与我相关
我的任务
分享
update ddBbsReply set ddFloor =
(
select count(*)
from ddBbsReply
where ddAttachTopic = ddReply.ddAttachTopic
and ddAddTime < ddReply.ddAddTime
) + 1
from ddBbsReply ddReply
var rs=createRecordset()
var rs2=createRecordset()
rs.open("select * from ddBbsTopic")
for(var i=0; i<rs.recordcount; i++){
rs2.open("select * from ddBbsReply where ddAttachTopic='"+rs("ddTopicID")+"' order by ddAddTime")
for(var o=0; o<rs2.recordcount; o++){
rs2("ddFloor")=(o+1)
rs2.moveNext()
}
rs2.close
}
recycle(rs2)
recycle(rs)
--明白了,我下面使用的是id<t.id,你换用addtime < t.addtime即可.
create table tb(id int,topic int,[floor] int, title varchar(20), addTime varchar(20))
insert into tb values(1, 1, null , '回复:你好' , '<日期时间>')
insert into tb values(2, 2, null , '回复:我不好', '<日期时间>')
insert into tb values(3, 1, null , '回复:你好' , '<日期时间>')
insert into tb values(4, 2, null , '回复:我不好', '<日期时间>')
go
select id , topic , [floor] = (select count(*) from tb where topic = t.topic and id < t.id) + 1 , title , addtime from tb t
drop table tb
/*
id topic floor title addtime
----------- ----------- ----------- -------------------- --------------------
1 1 1 回复:你好 <日期时间>
2 2 1 回复:我不好 <日期时间>
3 1 2 回复:你好 <日期时间>
4 2 2 回复:我不好 <日期时间>
(所影响的行数为 4 行)
*/