View Full Version : Count on Greater than and Less Than


fishingbighole
08-17-2002, 11:40 AM
I have a table that has the following:

Player Names
Team
Position (3 positions)
Scoring Code (3 types of codes)
Length of the score (some are duplicate yardages)
Year (3 years of data)

I am trying to write a query that will tell me how many times a player scored per a certain scoring code in the following increments:

Player Name
Pos.
Scoring Code
0-9 "distance"
10-19 "distance"
And so on.

Can someone help.

Jon K
08-17-2002, 08:02 PM
You can use the iif() function in a Total query (type in the SQL View of a new query, using the correct table name and field names):-

SELECT [Player Name], Position, [Scoring Code],
sum(iif([Length of Score] between 0 and 9,1,0)) AS [Distance 0-9],
sum(iif([Length of Score] between 10 and 19,1,0)) AS [Distance 10-19],
sum(iif([Length of Score] between 20 and 29,1,0)) AS [Distance 20-29],
sum(iif([Length of Score] between 30 and 39,1,0)) AS [Distance 30-39],
count(*) as Total
FROM [yourTable]
GROUP BY [Player Name], Position, [Scoring Code];


The square brackets are needed only if the table name and field names contain spaces. Add more [Length of Score] as it is needed.

Pat Hartman
08-20-2002, 08:26 PM
Select Player, [Scoring Code], Count(*) As CountOfScores
From YourTable
Group By Player, [Scoring Code];

Jon K
08-20-2002, 09:49 PM
I am confused. How do the CountOfScores relate to the Lengths of the score?

Pat Hartman
08-21-2002, 08:14 PM
Sorry Jon, I missed that part of the question. Your answer is fine.