use pubsdeclare @fid int
declare @milestone int
declare @count int
declare @val intset @fid = 1
set @milestone = 1
truncate table milestone--得到总的milestone数
select @count = count(1) / 10000
from thread
where fid = @fid--第一个milestone
select top 1
@val = lastpost
from thread with ( nolock )
where fid = @fid
and lastpost not in ( select top 10000
lastpost
from thread with ( nolock )
where fid = @fid
order by lastpost desc )
order by lastpost desc
insert into milestone
( fid, milestone, lastpostdesc )
values ( @fid, @milestone, @val )
set @milestone = @milestone + 1while ( @milestone <= @count )
begin
select top 1
@val = lastpost
from thread with ( nolock )
where fid = @fid
and lastpost < @val
and lastpost not in ( select top 10000
lastpost
from thread with ( nolock )
where fid = @fid
and lastpost < @val
order by lastpost desc )
order by lastpost desc
insert into milestone
( fid, milestone, lastpostdesc )
values ( @fid, @milestone, @val )
set @milestone = @milestone + 1
end
在SqlServer中我们常常合并多行语句然后直接执行,但是在mysql中如何执行以上语句呢?
我是想直接在代码里边执行,例如:
mySqlHelper.ExecuteQuery("这里是上面的sql语句");
如果是一般的多条SQL语句则可以通过分号来分隔即
select now(); select 1+1 ;
mysql要实现此功能必须在存储过程中实现的。