Step 1: Calculate the average finish for each year by dividing the sum of the 'finish' column by the number of races in that year. Add a column 'avg_finish' to the existing table.
year |
races |
wins |
poles |
top_5 |
top_10 |
dnf |
finish |
start |
winnings |
season_rank |
team__s_ |
1995 |
2 |
0 |
0 |
0 |
0 |
0 |
24.0 |
37.0 |
5225 |
75th |
stegell motorsports |
1996 |
14 |
0 |
0 |
0 |
0 |
6 |
26.4 |
25.1 |
63865 |
42nd |
stegell motorsports |
1997 |
28 |
0 |
1 |
0 |
1 |
10 |
27.1 |
21.6 |
196656 |
23rd |
stegell motorsports |
1998 |
31 |
0 |
1 |
0 |
3 |
5 |
24.9 |
25.5 |
335163 |
19th |
stegell motorsports |
1999 |
25 |
0 |
0 |
1 |
1 |
9 |
25.8 |
18.2 |
243810 |
24th |
curb - agajanian performance group |
2000 |
2 |
0 |
0 |
0 |
0 |
1 |
35.0 |
28.5 |
15900 |
90th |
alumni motorsports |
2001 |
33 |
0 |
0 |
0 |
0 |
6 |
27.9 |
32.7 |
491977 |
23rd |
hensley racing |
2002 |
24 |
0 |
0 |
0 |
1 |
11 |
27.0 |
33.0 |
288325 |
29th |
hensley racing |
2003 |
5 |
0 |
0 |
0 |
0 |
4 |
35.8 |
25.6 |
68360 |
85th |
jay robinson racing |
2004 |
9 |
0 |
0 |
0 |
0 |
6 |
31.4 |
37.2 |
139685 |
54th |
moy racing / jay robinson racing |
2005 |
7 |
0 |
0 |
0 |
0 |
7 |
40.9 |
32.6 |
108921 |
83rd |
jay robinson racing |
2006 |
9 |
0 |
0 |
0 |
0 |
7 |
38.9 |
39.1 |
151184 |
70th |
jay robinson racing |
2008 |
1 |
0 |
0 |
0 |
0 |
1 |
43.0 |
34.0 |
15674 |
149th |
jay robinson racing |
Step 2: Select rows where the 'year' is between 1995 and 2008 (inclusive).
year |
races |
wins |
poles |
top_5 |
top_10 |
dnf |
finish |
start |
winnings |
season_rank |
team__s_ |
avg_finish |
1995 |
2 |
0 |
0 |
0 |
0 |
0 |
24.0 |
37.0 |
5225 |
75th |
stegell motorsports |
12.0 |
1996 |
14 |
0 |
0 |
0 |
0 |
6 |
26.4 |
25.1 |
63865 |
42nd |
stegell motorsports |
1.8857142857142857 |
1997 |
28 |
0 |
1 |
0 |
1 |
10 |
27.1 |
21.6 |
196656 |
23rd |
stegell motorsports |
0.9678571428571429 |
1998 |
31 |
0 |
1 |
0 |
3 |
5 |
24.9 |
25.5 |
335163 |
19th |
stegell motorsports |
0.8032258064516129 |
1999 |
25 |
0 |
0 |
1 |
1 |
9 |
25.8 |
18.2 |
243810 |
24th |
curb - agajanian performance group |
1.032 |
2000 |
2 |
0 |
0 |
0 |
0 |
1 |
35.0 |
28.5 |
15900 |
90th |
alumni motorsports |
17.5 |
2001 |
33 |
0 |
0 |
0 |
0 |
6 |
27.9 |
32.7 |
491977 |
23rd |
hensley racing |
0.8454545454545455 |
2002 |
24 |
0 |
0 |
0 |
1 |
11 |
27.0 |
33.0 |
288325 |
29th |
hensley racing |
1.125 |
2003 |
5 |
0 |
0 |
0 |
0 |
4 |
35.8 |
25.6 |
68360 |
85th |
jay robinson racing |
7.159999999999999 |
2004 |
9 |
0 |
0 |
0 |
0 |
6 |
31.4 |
37.2 |
139685 |
54th |
moy racing / jay robinson racing |
3.488888888888889 |
2005 |
7 |
0 |
0 |
0 |
0 |
7 |
40.9 |
32.6 |
108921 |
83rd |
jay robinson racing |
5.8428571428571425 |
2006 |
9 |
0 |
0 |
0 |
0 |
7 |
38.9 |
39.1 |
151184 |
70th |
jay robinson racing |
4.322222222222222 |
2008 |
1 |
0 |
0 |
0 |
0 |
1 |
43.0 |
34.0 |
15674 |
149th |
jay robinson racing |
43.0 |
Step 3: Calculate the overall average finish by dividing the sum of the 'avg_finish' column by the number of rows.
year |
races |
wins |
poles |
top_5 |
top_10 |
dnf |
finish |
start |
winnings |
season_rank |
team__s_ |
avg_finish |
1995 |
2 |
0 |
0 |
0 |
0 |
0 |
24.0 |
37.0 |
5225 |
75th |
stegell motorsports |
12.0 |
1996 |
14 |
0 |
0 |
0 |
0 |
6 |
26.4 |
25.1 |
63865 |
42nd |
stegell motorsports |
1.8857142857142857 |
1997 |
28 |
0 |
1 |
0 |
1 |
10 |
27.1 |
21.6 |
196656 |
23rd |
stegell motorsports |
0.9678571428571429 |
1998 |
31 |
0 |
1 |
0 |
3 |
5 |
24.9 |
25.5 |
335163 |
19th |
stegell motorsports |
0.8032258064516129 |
1999 |
25 |
0 |
0 |
1 |
1 |
9 |
25.8 |
18.2 |
243810 |
24th |
curb - agajanian performance group |
1.032 |
2000 |
2 |
0 |
0 |
0 |
0 |
1 |
35.0 |
28.5 |
15900 |
90th |
alumni motorsports |
17.5 |
2001 |
33 |
0 |
0 |
0 |
0 |
6 |
27.9 |
32.7 |
491977 |
23rd |
hensley racing |
0.8454545454545455 |
2002 |
24 |
0 |
0 |
0 |
1 |
11 |
27.0 |
33.0 |
288325 |
29th |
hensley racing |
1.125 |
2003 |
5 |
0 |
0 |
0 |
0 |
4 |
35.8 |
25.6 |
68360 |
85th |
jay robinson racing |
7.159999999999999 |
2004 |
9 |
0 |
0 |
0 |
0 |
6 |
31.4 |
37.2 |
139685 |
54th |
moy racing / jay robinson racing |
3.488888888888889 |
2005 |
7 |
0 |
0 |
0 |
0 |
7 |
40.9 |
32.6 |
108921 |
83rd |
jay robinson racing |
5.8428571428571425 |
2006 |
9 |
0 |
0 |
0 |
0 |
7 |
38.9 |
39.1 |
151184 |
70th |
jay robinson racing |
4.322222222222222 |
2008 |
1 |
0 |
0 |
0 |
0 |
1 |
43.0 |
34.0 |
15674 |
149th |
jay robinson racing |
43.0 |
Step 4: Use a `CASE` statement to return TRUE if the overall average finish is equal to 31.39, otherwise return FALSE.
overall_avg_finish |
7.690247694957372 |