MySQL SQL 语句 - 选择此查询的逆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19682816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:17:01  来源:igfitidea点击:

SQL Statement - SELECT the inverse of this query

mysqlsqlinverse-transform

提问by Dev'Dev

I have this query and i want to select the inverse of what that select.

我有这个查询,我想选择那个选择的倒数。

SELECT Guide.id FROM Guide
INNER JOIN GuideAvailability ON Guide.id = GuideAvailability.guideId
WHERE GuideAvailability.startDate IN (1377946800)
GROUP BY GuideAvailability.guideId
HAVING COUNT(DISTINCT GuideAvailability.id) = 1

Is there a easy way to solve my problem ?

有没有简单的方法可以解决我的问题?

回答by Code L?ver

Simply use this query:

只需使用此查询:

SELECT * 
     FROM Guide where id NOT IN (
       SELECT Guide.id 
         FROM Guide
         INNER JOIN GuideAvailability ON Guide.id = GuideAvailability.guideId
         WHERE GuideAvailability.startDate IN (1377946800) 
         GROUP BY GuideAvailability.guideId 
         HAVING COUNT(DISTINCT GuideAvailability.id) = 1
      )

回答by Hisham

MAy be you are looking for this

可能你正在寻找这个

SELECT Guide.id FROM Guide
INNER JOIN GuideAvailability ON Guide.id = GuideAvailability.guideId
WHERE GuideAvailability.startDate NOT IN (1377946800) GROUP BY GuideAvailability.guideId HAVING COUNT(DISTINCT GuideAvailability.id) <> 1

回答by Extremesecrecy

You can flip the bool. ;)

你可以翻转布尔值。;)

I do this when I have a large amount of where filters and there is a specific exclusion set of filters. I write them inside the case and do =1to exclude and =0to find what I excluded.

当我有大量 where 过滤器并且有一组特定的排除过滤器时,我会这样做。我将它们写在案例中并=1排除并=0找到我排除的内容。

SELECT Guide.id FROM Guide
INNER JOIN GuideAvailability ON Guide.id = GuideAvailability.guideId
WHERE ( case when GuideAvailability.startDate IN (1377946800) then 1 else 0 end) = 0
GROUP BY GuideAvailability.guideId
HAVING COUNT(DISTINCT GuideAvailability.id) = 1