I have the following table:
Col1 Col2
A ...
A ...
A
B
B
C
D
I want to be able to consider A & B as if they were one for the purposes of group by, so that
select Col1, count(*) from table group by Col1
will return
Col1 count(*)
AB 5
C 1
D 1
Group on a conditional column via a
CASEstatement:You did not specify your RDBMS, but some (like MySQL) will permit you to use the alias
Col1Groupinside theGROUP BYrather than having to duplicate the whole expression down there.