Well it:
select Name, count(Id) from MyTable group by Name
will provide you with the following:
Harry Johns, 1 Adam Taylor, 1 John Smith, 2 Bill Manning, 1
and this (MS SQL syntax):
select Name + case when ( count(Id) > 1 ) then ' ('+cast(count(Id) as varchar)+')' else '' end from MyTable group by Name
will provide you with the following:
Harry Johns Adam Taylor John Smith (2) Bill Manning
Do you really want another John Smith at the end of your results?
EDIT: Oh, I see you want consecutive runs to be grouped. In this case, I would say that you need a cursor or do it in the program code.
Blorgbeard
source share