这是我的表数据: -
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (1,'Cinthol','cosmetic soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (1,'Cinthol','cosmetic soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (1,'Cinthol','cosmetic soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (1,'Lux','cosmetic soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (1,'Crowning Glory','cosmetic soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (2,'Cinthol','nice soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (3,'Lux','nice soap','soap');
Insert Into tblProduct (ProductId,ProductName,Description,Category) Values (3,'Lux','nice soap','soap');
当我发出此查询时: -
Select ProductId,
ProductName,
Description,
Category,
RANK() Over ( partition by ProductId Order By ProductId) As Rank
From tblProduct;
我所能看到的每一行都有1st
等级。所有其他其他职级在哪里?由于我没有使用2
,因此productid 6
的行应该具有等级DENSE_RANK()
。为什么查询不起作用?
答案 0 :(得分:3)
您正在按ProductId进行分区 - 这意味着每个“分区”将从1开始变换。尝试删除PARTITION BY ProductId
。