473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Top 4 values based on a group

I am working on a query that I would like to get the top 4 values based on a group. Here is the SQL:

SELECT qRenPercRept1.CountOfccName, qRenPercRept1.Merged, qRenPercRept1.ccName, qRenPercRept1.AvgOfcpUpcomingRen
FROM qRenPercRept1
ORDER BY qRenPercRept1.CountOfccName DESC;

I want the top 4 Merged based on Countofccname.

is this possible? I've tried a few different things that I have read online, but I keep getting "Data mistype" errors.

Thanks so much in advance!

LSGKelly
Feb 8 '10 #1
7 2044
yarbrough40
320 100+
is this what you want?..... what do you mean by "merged"?
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 4 qRenPercRept1.CountOfccName, qRenPercRept1.Merged, qRenPercRept1.ccName, qRenPercRept1.AvgOfcpUpcomingRen
  2. FROM qRenPercRept1
  3. ORDER BY qRenPercRept1.CountOfccName DESC;
  4.  
Feb 8 '10 #2
No, this is not what I need. I have two columns, one has the total amount of carriers [countofccname] and the other is called Merged, which is a field that has a list of Markets. What I need is the top four [countofccname] per Market.

It looks like this:

Atlanta, 32
Atlanta, 30
Atlanta, 25
Atlanta, 6
Atlanta, 1
Baltimore, 34
Baltimore, 32
Baltimore, 3
Baltimore, 2
Baltimore, 1

With Atlanta/Baltimore being the Merged field and the number representing [countofccname]

What I would like is for it to show me only the top four for each market, so my query would only pull the following:

Atlanta, 32
Atlanta, 30
Atlanta, 25
Atlanta, 6
Baltimore, 34
Baltimore, 32
Baltimore, 3
Baltimore, 2

There are also one other field in the query, AvgOfcpUpcomingRen which needs to be there.

Thanks again for your help!
Feb 8 '10 #3
yarbrough40
320 100+
Expand|Select|Wrap|Line Numbers
  1. SELECT top 4 qRenPercRept1.Merged, qRenPercRept1.countofccname
  2. FROM qRenPercRept1 
  3. Where qRenPercRept1.Merged = "Atlanta"
  4. UNION ALL
  5. SELECT top 4 qRenPercRept1.Merged, qRenPercRept1.countofccname
  6. FROM qRenPercRept1 
  7. Where qRenPercRept1.Merged = "Baltimore"
  8. ORDER BY qRenPercRept1.Merged, qRenPercRept1.CountOfccName DESC
  9.  
  10.  
Feb 8 '10 #4
I think we are getting closer, except Atlanta and Baltimore are just examples of the names in Merged. There are actually about 30 different Markets.
Feb 8 '10 #5
yarbrough40
320 100+
well you could keep adding unions all down the page to include all 30 markets. Access could run a query like that without breaking a sweat. The only other way is to use VBA to build two recordsets, one like so:
SELECT distinct Merged
FROM qRenPercRept1

this will get your unique markets. store that value in a variable and loop through them while applying that variable into your UNION query recordset.
Feb 8 '10 #6
Thank you so much for your help! I did it the first way. Works like a charm.

:)
Feb 8 '10 #7
Absolute genius...."SELECT TOP 4" ....i really gotta read more about SQL, bc not knowing that things like that are capable, are really slowing me down i am sure.
Feb 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
8
by: Boefje | last post by:
Hello, I need to get all records from a table where a for a given playerid no field enddate exists with value NULL. table player_team: id, playerid, startdate, enddate 1, ...
2
by: Zlatko Matiæ | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
16
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some...
4
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
3
by: Phoe6 | last post by:
Hi, Am starting a new thread as I fear the old thread which more than a week old can go unnoticed. Sorry for the multiple mails. I took the approach of Subclassing ConfigParser to support...
2
by: Rex | last post by:
Hi Below is a table with sample data to explain what I want to achieve. trackID member marker allele1 ------- ------ --------------------------------------------------...
7
convexcube
by: convexcube | last post by:
To keep a record of training levels for different tasks, I have 18 option groups with 4 options values each: 0 labelled as "None", 1 labelled as "Trainee", 2 labelled as "Competent" and 3 labelled as...
3
by: nassim.bouayad.agha | last post by:
Hello, I am seeking for information about conditional XSD validation based on elements values,but unfortunatly,I could not find a clear answer.Let's say that I have three XML elements named...
0
by: Maric Michaud | last post by:
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit : Disctionaries are hash tables with a unique key and constant time lookup. What you want could be implemented as a complex data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.