sql三重内部联接

eblbsuwk  于 2021-08-09  发布在  Java
关注(0)|答案(2)|浏览(393)

我想列出所有的球员谁的全球水平超过5,并已超过3场比赛

SELECT Players.Nickname, Accounts.Email, players.GlobalLevel
FROM Players
INNER JOIN Accounts on Accounts.AccountID = Players.PlayerID
INNER JOIN PlayHistory on Players.PlayerID = PlayHistory.PlayerID
WHERE Players.GlobalLevel >5 AND PlayHistory.MatchID >3
ORDER BY Players.Nickname ASC

但结果给了我这个。选择了多个名称

nr9pn0ug

nr9pn0ug1#

您需要匹配的计数超过3个不匹配的\u id:

SELECT Players.Nickname, Accounts.Email, 
players.GlobalLevel,count(PlayHistory.MatchID) matchCount
FROM Players
INNER JOIN Accounts on Accounts.AccountID = Players.PlayerID
INNER JOIN PlayHistory on Players.PlayerID = PlayHistory.PlayerID
WHERE Players.GlobalLevel >5 
GROUP BY  Players.Nickname, Accounts.Email, players.GlobalLevel
HAVING count(PlayHistory.MatchID) >3
ORDER BY Players.Nickname ASC
nxagd54h

nxagd54h2#

试试这个-

SELECT Players.Nickname, Accounts.Email, players.GlobalLevel
      FROM Players
                                      --Replace PlayerId to AccountId
      INNER JOIN Accounts on Accounts.AccountID = Players.AccountID   

     INNER JOIN PlayHistory on Players.PlayerID = PlayHistory.PlayerID
       WHERE Players.GlobalLevel >5 AND PlayHistory.MatchID >3
      ORDER BY Players.Nickname ASC

相关问题