dsft8327 2014-02-01 01:13
浏览 29
已采纳

sql查询没有返回正确的结果

Ive got a table containing results for a certain sport competition from 2009 - present. The table contains numerous columns such as hometeam, awayteam, homescore, awayscore etc. As you can see from the image below:

enter image description here

If I want to display results for a certain team (in this example team Sharks) for both home and away matches I do it like so:

    SELECT *
FROM `results`
WHERE `hometeam` = 'Sharks' || `awayteam` = 'Sharks'

The above code is working fine and I get the correct results as you can see from the image:

enter image description here

The problem

The problem im having is when I want to display BOTH home and away match results for only two SPECIFIC teams, im not getting the correct results. (In the query below im trying to only display home and away results when team Stormers played against team Sharks) I query the table as follows:

SELECT *
FROM `results`
WHERE `hometeam` = 'Stormers' || `awayteam` = 'Stormers' && `hometeam` = 'Sharks' || `awayteam` = 'Sharks'

You can see from the image below that the above query is returning the wrong results. The query is returning results for both team Stormers and team Sharks for ALL their home and away matches against ALL opponents

enter image description here

The question

Im looking for a way where the query will only return results for specific teams when they played against each other home and away. Example: for this query I only wanted to display all results for team Stormers against team Sharks, ignoring all other opponents.

If anyone can be so kind to point me in the right direction it would be greatly appreciated. Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dongwuxie5112 2014-02-01 01:16
    关注

    I looks like you just have wrong logic. Try this:

    SELECT *
    FROM `results`
    WHERE (`hometeam` = 'Stormers' AND `awayteam` = 'Sharks')
    OR (`hometeam` = 'Sharks' AND `awayteam` = 'Stormers')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?