*/ First, get on a per name basis the first year they have a transaction
*/ for... in addition to the total transactions this person has regardless
*/ of the year.. ex: your two overlap of "a" and "c" persons
SELECT ;
YT.Name,;
MIN( YEAR( YT.DATE )) as FirstYear,;
COUNT(*) as TotalPerName;
FROM ;
YourTable YT;
GROUP BY ;
1;
INTO ;
CURSOR C_ByNameTotals
*/ Now that you have totals based on the first year per person with their total
*/ entries regardless of the year, get the year and sum of totals that HAVE
*/ entries for a given year.... THEN UNION for all original year possibilities
*/ that were NOT IN the C_ByNameTotals result set. (hence your 2007 and 2008)
SELECT;
FirstYear as FinalYear,;
SUM( TotalPerName ) as YrCount;
FROM ;
C_ByNameTotals;
GROUP BY ;
1;
INTO ;
CURSOR C_FinalResults;
UNION;
SELECT DISTINCT;
YEAR( Date ) as FinalYear,;
0 as YrCount;
FROM ;
YourTable ;
WHERE ;
YEAR( Date ) NOT IN ;
( select FirstYear FROM C_ByNameTotals )