In article <1174783709.988164.47760
@b75g2000hsg.googlegroups.com>,
chrislabs12@gmail.com says...
Quote:
I have a table that lists years and other fields I want to count the
years but if the years are equal I want it to add 1 each time. for
example
>
Year count
1990 1
1991 1
1992 1
1992 2
1992 3
1993 1
1993 2
1994 1
1995 1
1996 1
1996 2
1996 3
>
Any help would be appreciated.
>
>
It seems that you are grouping by year and ranking within year.
If the table also has a unique column to break ties, then maybe
something like this:
SELECT table1.table_id,
table1.year_nbr,
(SELECT COUNT(* )
FROM table1 AS b
WHERE table1.year_nbr = b.year_nbr
AND table1.table_id >= b.table_id) AS
year_count
FROM table1
GROUP BY table1.table_id,table1.year_nbr;
table_id year_nbr year_count
1 1990 1
2 1991 1
3 1992 1
4 1992 2
5 1992 3
6 1993 1
7 1993 2
8 1994 1
9 1995 1
10 1996 1
11 1996 2
12 1996 3