SQL Statement - SELECT the inverse of this query

前端 未结 3 1021
广开言路
广开言路 2021-01-05 05:29

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 = GuideAvailabili         


        
相关标签:
3条回答
  • 2021-01-05 05:34

    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
          )
    
    0 讨论(0)
  • 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 =1 to exclude and =0 to find what I excluded.

    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
    
    0 讨论(0)
  • 2021-01-05 05:54

    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
    
    0 讨论(0)
提交回复
热议问题