Next problem: LIKE.
If I simplify the inner query in the above example to this
Code:
SELECT x
FROM y
WHERE z IN ('a','b','c')
GROUP BY x.id
HAVING COUNT(DISTINCT z) = 3
I could rewrite it as
Code:
SELECT x
FROM y
WHERE z = 'a' OR z = 'b' OR z = 'c'
GROUP BY x.id
HAVING COUNT(DISTINCT z) = 3
and then introduce a LIKE like this:
Code:
SELECT x
FROM y
WHERE z = 'a' OR z = 'b' OR z LIKE 'c%'
GROUP BY x.id
HAVING COUNT(DISTINCT z) = 3
But that won't give me what I want (a, b and c), since it will also retrieve b, cd and ce; cd, ce and cf; etc.
So I tried
Code:
SELECT x
FROM y
WHERE z = 'a' OR z = 'b' OR z LIKE 'c%'
GROUP BY x.id
HAVING COUNT(DISTINCT z) = 3
AND COUNT(z NOT LIKE 'c%') = 2
which doesn't work either.
Nor does
Code:
SELECT x
FROM y
WHERE z = 'a' OR z = 'b' OR z LIKE 'c%'
GROUP BY x.id
HAVING COUNT(DISTINCT z) = 3
AND COUNT(z = 'a') = 1
AND COUNT(z = 'b') = 1
Any suggestions what I should try next?
Bookmarks