嗨我有一个synerio,用户映射到两个角色,角色的优先级设置为1和2 ......我的问题是如何只访问最高代码和角色......
对于exp
Code Name Role RolePriority
1 Rehman Abc 2
2 Rehman Def 3
3 Neha Des 1
所以我希望Rehman扮演Def角色,Neha扮演Des角色
答案 0 :(得分:0)
您可以使用ROW_NUMBER() OVER()
选择最高优先级
DECLARE @test AS TABLE(Code INT,Name VARCHAR(100),Role VARCHAR(100),RolePriority int)
INSERT INTO @test VALUES(1,'Rehman','Abc',2),(2,'Rehman','Def',3),(3,'Neha','Des',1)
SELECT * FROM(
SELECT *,ROW_NUMBER() OVER(PARTITION BY Name ORDER BY RolePriority desc) AS
rw FROM @test)res
WHERE rw = 1