)
现在,在这种情况下,不同的值是相同的user Id,其余的相同。
user Id
|UserId | First name | Last name | IsRequired | IsDeleted | 1 harry tom true false 3 harry tom true false 3 ram sham true false
我需要两个条目之一,但是上面链接中提到的场景也应该是它们。
预期结果
| UserId | First name | Last name | IsRequired | IsDeleted | 1 harry tom true false 3 ram sham true false
用户ID可以是 1 or 3
1 or 3
试试这个 !
create table users(UserId int, Firstname varchar(30), Lastname varchar(30), IsRequired varchar(5), IsDeleted varchar(5)); insert into users values('1','harry','tom','true','false'); insert into users values('1','harry','tom','false','false'); insert into users values('3','ram','sham','true','false'); select * from ( select *,rn=ROW_NUMBER()over(partition by UserId order by Firstname desc) from users )x where x.rn=1
[See demo](http://www.sqlfiddle.com/#!6/89cbc/1)