从表中删除具有最高值的条目

时间:2015-11-07 21:06:01

标签: sql

  • PLAYER(playerId,playerName)
  • LEVEL(levelId,levelName)
  • GAME(playerId,levelId,time)

我想删除levelId = 1

上时间最长的玩家

我试过

DELETE FROM PLAYER
WHERE playerId = SELECT playerId 
                 FROM Game G
                 WHERE G.levelId = 1
                 AND G.time >= ALL(SELECT time FROM GAME 
                                   WHERE G.levelId = levelId);

这个解决方案..是不是? 还有更好的吗?

1 个答案:

答案 0 :(得分:1)

意味着您要删除任何播放器,这意味着

DELETE FROM PLAYER WHERE playerId = any( SELECT playerId FROM Game G
WHERE G.levelId=1
AND
G.time>=ALL(SELECT time FROM GAME WHERE G.levelId=levelId));