国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

用一個實例講解如何正確使用數(shù)據(jù)庫游標

2024-07-21 02:42:31
字體:
供稿:網(wǎng)友
在下面的示例中,表className中有如下分類:

具體示例:

classID className

1 衣服

2 褲子

5 帽子

10 鞋子

表PRoductInfo有如下記錄:

productID productName parentID clickNum

1 男士衣服 1 90 --衣服類別中這條記錄的點擊率最高

2 女士衣服 1 80

3 男士褲子 2 70

4 女士褲子 2 90

--褲子類別中這條記錄點擊率最高

5 男士帽子 5 15

6 女士帽子 5 30

帽子類別中這條點擊率最高

7 男士鞋子 10 65

--鞋子類別中這條點擊率最高

8 女士鞋子 10 52

9 女士鞋子1 10 54

現(xiàn)在我們要求分別把衣服,褲子,帽子,鞋子這些類別中點擊率最高的一條記錄找出來,然后再降序排列,結(jié)果如下:

productID productName clickNum

1 男士衣服 90

4 女士褲子 90

7 男士鞋子 65

6 女士帽子 30

實現(xiàn)方法:

declare @temp table

(

productID int,

productName nvarchar(30),

clickNum int

)

declare @classID int

declare cursor_classID cursor

for

select classID from dbo.className

open cursor_classID

fetch next from cursor_classID into @classID

--0 表示 FETCH 語句成功

while @@FETCH_STATUS=0

begin

insert into @temp

select top 1 productID,productName,clickNum from dbo.productInfo

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


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金川县| 虎林市| 建平县| 青冈县| 越西县| 兰溪市| 四子王旗| 芜湖县| 县级市| 武鸣县| 开封市| 张掖市| 盘锦市| 隆林| 安新县| 游戏| 壤塘县| 抚远县| 红桥区| 佛山市| 闽清县| 静宁县| 曲沃县| 临桂县| 马龙县| 铁岭市| 云梦县| 宁强县| 枣庄市| 年辖:市辖区| 小金县| 廉江市| 海门市| 常熟市| 彝良县| 吉木萨尔县| 凤阳县| 凤冈县| 肥东县| 峨眉山市| 高邮市|