Assuming a DB like this:
Date | Attribute1 | Attribute2 | ... | AttributeN
-------------------------------------------------
1 | A | C | ... | ...
1 | B | C | ... | ...
2 | A | A | ... | ...
2 | B | B | ... | ...
2 | A | A | ... | ...
3 | B | B | ... | ...
3 | A | A | ... | ...
4 | B | C | ... | ...
4 | A | A | ... | ...
I am trying to find for which unique dates (they are actual date
s in the real case but I don't think that matters), ALL elements of Attribute1
are equal to their corresponding elements in Attribute2
. The result for the example data above would be
Date
----
2
3
Because for each record that has date
equal to 2
(and the same for 3
) , Attribute1
is equal to Attribute2
. 4
is not returned because although the last record in the sample does meet the criterion (since A
equals A
), the second last record does not (since B
does not equal C
).
I could not work out how to write this query, I was hoping for some aggregate function (shown as ALL(...)
in the code below) that would allow me to write something like:
SELECT Date
FROM myTable
GROUP BY Date
HAVING ALL(Attribute1 = Attribute2)
Is there such a function? Otherwise is there a clever way to this using COUNT
maybe?