我有一个玩家列表和他们在游戏中的分数列表。我想比较两列,并返回值1或0. 1 =最高数字,0 =最低数字。如果两个值相等,我想返回两个1。
如何使用Excel或SQL Server 2012执行此操作?
答案 0 :(得分:2)
如果我理解正确,你希望团队中得分最高的玩家标记为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)
当然我猜到了列的名称,所以你必须调整它。