SELECT语句是否为每条记录重复得分?

时间:2018-12-10 19:10:12

标签: sql oracle join select

我正在尝试编写SELECT语句,以显示在球队输了的比赛中原始得分超过190的保龄球。

此代码检索960个结果,每个人的得分都为192或193,每个团队中的每个人都显示出来,并且每个团队在同一游戏中玩多次。

SELECT bs.MATCHID "Match", t.TEAMNAME "Team Name", 
   b.BOWLERFIRSTNAME || ' ' || b.BOWLERLASTNAME "Bowler Name", 
   bs.GAMENUMBER "Game Number", bs.RAWSCORE "Raw Score"
FROM BOWLER_SCORES bs, TEAMS t, BOWLERS b, MATCH_GAMES m
WHERE bs.MATCHID = m.MATCHID
AND bs.GAMENUMBER = m.GAMENUMBER
AND bs.WONGAME = 'N'
AND bs.RAWSCORE >= 190;

您可以看到这显然是错误的,从根本上讲,我在代码中做错了什么。我只是不确定它是什么,以及我应该做些什么。

我对SQL还是很陌生,因此非常感谢您提供的任何其他建议或指针。

1 个答案:

答案 0 :(得分:2)

非常感谢xQbert和Gordon Linoff!

我现在正确显示了它!

这是更新的代码段:

SELECT DISTINCT MATCHID "Match", TEAMNAME "Team Name", 
   BOWLERFIRSTNAME || ' ' || BOWLERLASTNAME "Bowler Name", 
   bs.GAMENUMBER "Game Number", bs.RAWSCORE "Raw Score"
FROM BOWLERS
   JOIN TEAMS USING (TEAMID)
   JOIN BOWLER_SCORES bs USING (BOWLERID)
   JOIN MATCH_GAMES m USING (MATCHID)
WHERE bs.WONGAME = 'N'
  AND bs.RAWSCORE >= 190
ORDER BY "Match" ASC;