mysql - Selecting a GROUP BY statement only when a predicate is true on all grouped fields -
I have a table like this:
-------- ------ | ID | A. ------------- | 1 | 2 | | 1 | 5 | | 1 | 6 | | 2 | 6 | | 2 | 9 | ------------- How can I select all those IDs which have the values of A, which do not include certain numbers, such as I do not want any id for example (9, -1, 20) ID?
Thank you!
Believe that you only want id1 because the value of id for id2 is IN (9, -1.20) is what you want:
SELECT T1.id, t1.A from my_table t1 join the left my_table t2 at t2.id = t1.id and Select t2.A IN (9, -1, 20) where t2.id is Null or
my_table T1 ID where not exist ( Choose from my_table T2 WHERE t2.id = t1.id and t2.A IN (9, -1, 20)) / code>
Comments
Post a Comment