SQL:枚举每个组中返回的行

时间:2016-06-22 12:39:31

标签: sql oracle

假设我有<ButtonGroup> <Button onClick = {this.onSubmit.bind(this,1)} key={1} active = {this.state.i == 1}>LEFT</Button> <Button onClick = {this.onSubmit.bind(this,2)} key={2} active = {this.state.i == 2}>MIDDLE</Button> <Button onClick = {this.onSubmit.bind(this,3)} key={3} active = {this.state.i == 3}>RIGHT</Button> </ButtonGroup> onSubmit(new_i: number) { this.setState({ i: new_i }); } 查询返回某事。像这样:

SELECT ...

是否可以添加另一列枚举每个组中的行(即,枚举任何其他角色的经理,工作人员和人员而不考虑其他角色)?像这样:

role      name
--------  -------
MANAGER   Alice
WORKER    Bob
WORKER    Evan
WORKER    John
MANAGER   Max
WORKER    Steve

使用Oracle扩展程序很好。

1 个答案:

答案 0 :(得分:3)

使用窗口功能:

select role, name, 
       row_number() over (partition by role order by name) as rn
from the_table
order by name;