首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excel Rank与SQL Rank

Excel Rank与SQL Rank
EN

Stack Overflow用户
提问于 2018-12-07 10:06:21
回答 2查看 668关注 0票数 2

我有以下困境。

我需要在rank中对数据进行排序,就像我在SQL中对数据进行排序一样,如下所示:

代码语言:javascript
复制
declare @table table
(id int identity primary key , batchid int)

insert into @table (batchid) select 10
insert into @table (batchid) select 35
insert into @table (batchid) select 35
insert into @table (batchid) select 35
insert into @table (batchid) select 8
insert into @table (batchid) select 21
insert into @table (batchid) select 10
insert into @table (batchid) select 11
insert into @table (batchid) select 4
insert into @table (batchid) select 10
insert into @table (batchid) select 11
insert into @table (batchid) select 4
insert into @table (batchid) select 21
insert into @table (batchid) select 8
insert into @table (batchid) select 21
insert into @table (batchid) select 8
insert into @table (batchid) select 21
insert into @table (batchid) select 4
insert into @table (batchid) select 21
insert into @table (batchid) select 10
insert into @table (batchid) select 21
insert into @table (batchid) select 11
insert into @table (batchid) select 21
insert into @table (batchid) select 8
insert into @table (batchid) select 21
insert into @table (batchid) select 10
insert into @table (batchid) select 21
insert into @table (batchid) select 10
insert into @table (batchid) select 21

select
batchid
,   rank() over (partition by batchid order by id)  [RANK]
from    @table

我看了很多YouTube视频和关于如何在Excel中使用rank的教程,但是我没有看到在上面的代码中可以看到rankpartition by选项。

参见下面的上述脚本的结果:

在Excel中可以使用什么公式来实现相同的结果?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-07 10:11:44

简单的公式很容易实现:

在单元格B1中,输入初始值1。然后,在B2中输入一个公式:

代码语言:javascript
复制
=IF(A1=A2,B1+1,1)

那就一直拖下去。

票数 0
EN

Stack Overflow用户

发布于 2018-12-07 10:12:30

检查苏普特。示例来自,这里

选择数据旁边的空白单元格,例如C2,键入此公式,

代码语言:javascript
复制
=SUMPRODUCT(($A$2:$A$11=A2)*(B2<$B$2:$B$11))+1 

然后将自动填充句柄向下拖动,以将此公式应用于所需的单元格。 在公式中,A2:A11是包含组值的范围,A2是组值列表中的第一个单元格,B2是需要排列的列表中的第一个单元格,B2:B11是包含排序所需值的列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53667289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档