在Excel或SQL Server 2012中比较两个数字,并将值1或0设置为最高或最低值

我有一个球员名单和他们在比赛中的分数列表。 我想比较两列,并返回1或0的值。1 =最高编号,0 =最低编号。 如果两个值相等,我想返回两个1。

我怎样才能使用Excel或SQL Server 2012做到这一点?

如果我正确地理解了你,你希望队中得分最高的球员被标记为1,最低的被标记为0.在这种情况下:

 SELECT t.team_id,t.player_id,t.score, case when t.score = s.max_score then 1 when t.score = s.min_score then 0 end as pro_ind FROM YourTable t INNER JOIN(select team_id,max(score) as max_score,min(score) as min_score FROM YourTable GROUP BY team_id) s ON (t.team_id = s.team_id) 

当然,我猜想了列的名字,所以你将不得不调整它。