Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Top Ten Records From Four Different Groups

Status
Not open for further replies.

JHopman

Technical User
Jun 22, 2004
2
US
I am working on an accident database for a four county area. I need to find the top 10 accident locations for each county for a report. I am currently using a query with DISTINCTROW to group identical streets in each county and find out both the number of accidents, and the total number of injuries or dead.

SELECT DISTINCTROW [tblAccidentData].[DE_COUNTYNAMETXT] AS County, [tblAccidentData].[DE_RDWYNAMETXT] AS Location, [tblAccidentData].[DE_INTERNAMETXT] AS Intersection, (Sum([tblAccidentData].[DE_INJUREDNMB])+Sum([tblAccidentData].[DE_DEADNMB])) AS [Injury / Fatality], Count(*) AS [Total Accidents]
FROM tblAccidentData
WHERE ((([tblAccidentData].[DE_RDWYNAMETXT])<>"") And (([tblAccidentData].[DE_INTERNAMETXT])<>"") And (Year([tblAccidentData].[DE_COLLDTE])=[Accident Year]))
GROUP BY [tblAccidentData].[DE_COUNTYNAMETXT], [tblAccidentData].[DE_RDWYNAMETXT], [tblAccidentData].[DE_INTERNAMETXT]
ORDER BY [tblAccidentData].[DE_COUNTYNAMETXT], Count(*) DESC , [tblAccidentData].[DE_RDWYNAMETXT], [tblAccidentData].[DE_INTERNAMETXT];

I found that I could use the "TOP 10" command in my query to limit my results to the first ten records returned, but then I only end up with 10 records for the first county. I should end up with 40 records (10 for each county). I think I need to limit the print out using the Report, but I don't know how. Thanks in advance for your help.
 
How about using 4 different queries (10 for each) and 1 union query that brings them all together. Then using this as your datasource.
 
Have a look at this thread

Thread181-852291

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top