在下面的示例中
具體示例
classID className
表productInfo有如下記錄
productID productName parentID clickNum
——褲子類別中這條記錄點擊率最高
帽子類別中這條點擊率最高
——鞋子類別中這條點擊率最高
現在我們要求分別把衣服
productID productName clickNum
實現方法
declare @temp table
(
productID int
productName nvarchar(
clickNum int
)
declare @classID int
declare cursor_classID cursor
for
select classID from dbo
open cursor_classID
fetch next from cursor_classID into @classID
——
while @@FETCH_STATUS=
begin
insert into @temp
select top
where parentID = @classID
order by clickNum desc
fetch next from cursor_classID into @classID
end
close cursor_classID
deallocate cursor_classID
select * from @temp order by clickNum desc
From:http://tw.wingwit.com/Article/program/Oracle/201311/18574.html