📄 sqlquery2.sql
字号:
/*
表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
现在要求分别把衣服,裤子,帽子,鞋子这些类别中点击率最高的一条记录找出来,然后再降序排列,结果应如下:
productID productName clickNum
1 男士衣服 90
4 女士裤子 90
7 男士鞋子 65
6 女士帽子 30
*/
/*
create table className(classID int, classname varchar(10))
insert className select 1,'衣服'
insert className select 2,'裤子'
insert className select 5,'帽子'
insert className select 10,'鞋子'
create table productInfo(productID int IDENTITY(1,1), productName varchar(10),parentID int,clickNum int)
insert productInfo select '男士衣服',1,90
insert productInfo select '女士衣服',1,80
insert productInfo select '男士裤子',2,70
insert productInfo select '女士裤子',2,90
insert productInfo select '男士帽子',5,15
insert productInfo select '女士帽子',5,30
insert productInfo select '男士鞋子',10,65
insert productInfo select '女士鞋子',10,52
insert productInfo select '女士鞋子1',10,54
*/
/*
*/
select * from productInfo
select * from className
select a.parentID, b.clickNum,a.productName
from productInfo a , (select parentID, max(clickNum) clicknum from productInfo group by parentID) b
where a.parentID=b.parentID and a.clickNum=b.clickNum
order by a.clickNum desc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -