MySQL A or B but NOT both

自作多情 提交于 2019-12-02 12:38:35

Something like this should satisfy the specification:

SELECT f.bar 
  FROM frequents f
 WHERE f.drinker IN ('John','Rebecca')
 GROUP 
    BY f.bar
HAVING COUNT(DISTINCT f.drinker) < 2

  • get all of bar for 'John' and/or 'Rebecca'
  • collapse the rows to a single row for each bar
  • get a count of drinker for each bar
  • discard rows that have a count of 2 (i.e. both John and Rebecca)
  • leaving only values of bar for John and not Rebecca or vice versa
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!