sql三重内部联接

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

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

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

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

nr9pn0ug

nr9pn0ug1#

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

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

nxagd54h2#

试试这个-

  1. SELECT Players.Nickname, Accounts.Email, players.GlobalLevel
  2. FROM Players
  3. --Replace PlayerId to AccountId
  4. INNER JOIN Accounts on Accounts.AccountID = Players.AccountID
  5. INNER JOIN PlayHistory on Players.PlayerID = PlayHistory.PlayerID
  6. WHERE Players.GlobalLevel >5 AND PlayHistory.MatchID >3
  7. ORDER BY Players.Nickname ASC

相关问题