I have a table like the following:
ID Output
-------------------------
01ABC1 AB
01ABC2 AB
01ABC3 AB
02ABC1 AC
02ABC2 AC
02ABC3 AB
I have to count the number of sets of ID’s that has the same first two digits and the output is consistent.
For example in this case
01ABC1,01ABC2 and 01ABC3 has the same output but 02ABC1,02ABC2 and 02ABC3 does not.
So the answer will be 1 set.
The output should be
ID Count(ID)
---------------------------
01ABC 1
02ABC 0
If by
consistentyou meanall the outputs are the same for a given set of ids that share the same first 2 digits, then this query will do the work:PS: You’ve edited your question. This answers answer your second edit… the one with this expected result: