I'm new to SQL and need some advice on performing various calculations. If someone could point me down the right path to get information on how to do these things I would appreciate it.
I'm trying to create a Racing Statistical Program. You can see thread "Selecting data with criteria from 3 or 4 tables thread 181-1301486" to see the beginning of creating a basic record set for the project.
I'm able to pull the records from an Access DB that I need but I don't know how to manipulate them. I've created a recordset that has basic calculations in it (SUM, AVG, COUNT, Etc.). The next step is that I need to do some more complicated calculations.
Here would be a recordset.
DriverName
TotalPoints - SUM(Results.ResultsPoints)
TotalStarts - COUNT(Results.ResultsPoints)
AvgPoints - AVG(Results.ResultsPoints)
High - MIN(Results.ResultsFinish)
AvgStart - AVG(Results.ResultsStart)
AvgFinish - AVG(Results.ResultsFinish)
TotalLaps - SUM(Events.EventLaps)
LapsComplete - SUM(Results.ResultsLapsComplete)
%LapsComplete - Calculate using prev. columns
AvgLast3
AvgLast4
AvgLast6
AvgLast8
HOT6
HOT8
One of the things that I need to calculate are averages at intervals. At a minimum I need to average out the points earned (per driver) over the last 3 races, 4 races, 6, & 8 races.
From there I then need to use those averages and perform some calculations on them. (They are so easy to do in Excel). Here are the basic calculations that I need to perform.
Delta-1 = Avg Past 6 - Season Average
Delta-2 = Avg Past 3 - Avg Past 6
(.75*Delta-2) + (.25*Delta-1)This would be the HOT6 & HOT8 in the result set above.
Next, Top 5's & Top 10's. This would be how many times the driver finished in the Top 5 and in the Top 10. I tried to do something like Count(Points < 6) which didn't work. So how do you count the number of times a field meets a criteria?
Percentages - How do you calculate percentages on fields in the result set? For example, you have columns that are the results of Total Starts (TS) and Number of Top 5's (T5). How do I perform the calculations on those 2 columns.
I'ld like to tackle this mess myself but I need pointed in the right direction. I don't know if all of this can be done with SQL or a combination of SQL and VB code. What Methods/Functions/Aggregates can I use? Subqueries? How many, broken down where? I have access to quite a few books but I need to know what to go looking for.
I'm trying to create a Racing Statistical Program. You can see thread "Selecting data with criteria from 3 or 4 tables thread 181-1301486" to see the beginning of creating a basic record set for the project.
I'm able to pull the records from an Access DB that I need but I don't know how to manipulate them. I've created a recordset that has basic calculations in it (SUM, AVG, COUNT, Etc.). The next step is that I need to do some more complicated calculations.
Here would be a recordset.
DriverName
TotalPoints - SUM(Results.ResultsPoints)
TotalStarts - COUNT(Results.ResultsPoints)
AvgPoints - AVG(Results.ResultsPoints)
High - MIN(Results.ResultsFinish)
AvgStart - AVG(Results.ResultsStart)
AvgFinish - AVG(Results.ResultsFinish)
TotalLaps - SUM(Events.EventLaps)
LapsComplete - SUM(Results.ResultsLapsComplete)
%LapsComplete - Calculate using prev. columns
AvgLast3
AvgLast4
AvgLast6
AvgLast8
HOT6
HOT8
One of the things that I need to calculate are averages at intervals. At a minimum I need to average out the points earned (per driver) over the last 3 races, 4 races, 6, & 8 races.
From there I then need to use those averages and perform some calculations on them. (They are so easy to do in Excel). Here are the basic calculations that I need to perform.
Delta-1 = Avg Past 6 - Season Average
Delta-2 = Avg Past 3 - Avg Past 6
(.75*Delta-2) + (.25*Delta-1)This would be the HOT6 & HOT8 in the result set above.
Next, Top 5's & Top 10's. This would be how many times the driver finished in the Top 5 and in the Top 10. I tried to do something like Count(Points < 6) which didn't work. So how do you count the number of times a field meets a criteria?
Percentages - How do you calculate percentages on fields in the result set? For example, you have columns that are the results of Total Starts (TS) and Number of Top 5's (T5). How do I perform the calculations on those 2 columns.
I'ld like to tackle this mess myself but I need pointed in the right direction. I don't know if all of this can be done with SQL or a combination of SQL and VB code. What Methods/Functions/Aggregates can I use? Subqueries? How many, broken down where? I have access to quite a few books but I need to know what to go looking for.