DECLARE mycursor CURSOR for (select fatherID from dbo.Comment where $partition.fatherIDFunction(fatherID)=1 Group by fatherID) DECLARE @tempFatherID bigint open mycursor fetch next from mycursor into @tempFatherIDwhile(@@FETCH_STATUS=0) begin select CommentID,replyTime from Comment where $partition.fatherIDFunction(fatherID)=1 endclose mycursor deallocate mycursor
FROM T
WHERE fatherID=XXX
比如
1 ee 0
2 dd 1
3 dd 1
4 mm 2
.....
如果fatherid=1
是不是只要
2 dd 1
3 dd 1
select *
from tb
where fatherid in (
select fatherid
from tb
group by fatherid
having count(*) > 1
)
--存在主键字段,假设为Idselect *
from tb t
where exists (select 1 from tb where fatherid=t.fatherid and id<>t.id)
where $partition.fatherIDFunction(fatherID)=1
Group by fatherID)
DECLARE @tempFatherID bigint
open mycursor
fetch next from mycursor into @tempFatherIDwhile(@@FETCH_STATUS=0)
begin
select CommentID,replyTime from Comment where $partition.fatherIDFunction(fatherID)=1
endclose mycursor
deallocate mycursor