A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

First 10 numbers



 
 
Thread Tools Display Modes
  #1  
Old April 26th, 2010, 08:01 PM posted to microsoft.public.access.queries
Deenos
external usenet poster
 
Posts: 4
Default First 10 numbers

I have a query that pulls together states from a program. I group the states
and added the Count aggregate to the state field. I want access to display
the top 10 states including an extra entry if two states have the same number.

I hope this is clear.

thank you,
--
Deenos
  #2  
Old April 26th, 2010, 08:40 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default First 10 numbers

Using top 10 should work

SELECT TOP 10 States, Count(SomeField)
FROM SomeTable
GROUP BY States
ORDER BY Count(SomeField) Desc

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Deenos wrote:
I have a query that pulls together states from a program. I group the states
and added the Count aggregate to the state field. I want access to display
the top 10 states including an extra entry if two states have the same number.

I hope this is clear.

thank you,

  #3  
Old April 26th, 2010, 08:47 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default First 10 numbers

Open the query in SQL View. Change the first line to say:

SELECT TOP 10 state

Make sure to sort (AKA group by) the Count([State]) field in DESC order.

However the above will only return extra records if there is a tie for the
10th position. A tie for only the 5th position will only return 10 records.
If there are more than 2 records tied for 10th, all ties will be returned.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Deenos" wrote:

I have a query that pulls together states from a program. I group the states
and added the Count aggregate to the state field. I want access to display
the top 10 states including an extra entry if two states have the same number.

I hope this is clear.

thank you,
--
Deenos

  #4  
Old April 27th, 2010, 07:20 PM posted to microsoft.public.access.queries
Deenos
external usenet poster
 
Posts: 4
Default First 10 numbers

Great. Thank you. It worked
--
Deenos


"John Spencer" wrote:

Using top 10 should work

SELECT TOP 10 States, Count(SomeField)
FROM SomeTable
GROUP BY States
ORDER BY Count(SomeField) Desc

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Deenos wrote:
I have a query that pulls together states from a program. I group the states
and added the Count aggregate to the state field. I want access to display
the top 10 states including an extra entry if two states have the same number.

I hope this is clear.

thank you,

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.