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
7 2044
is this what you want?..... what do you mean by "merged"? -
SELECT TOP 4 qRenPercRept1.CountOfccName, qRenPercRept1.Merged, qRenPercRept1.ccName, qRenPercRept1.AvgOfcpUpcomingRen
-
FROM qRenPercRept1
-
ORDER BY qRenPercRept1.CountOfccName DESC;
-
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!
-
SELECT top 4 qRenPercRept1.Merged, qRenPercRept1.countofccname
-
FROM qRenPercRept1
-
Where qRenPercRept1.Merged = "Atlanta"
-
UNION ALL
-
SELECT top 4 qRenPercRept1.Merged, qRenPercRept1.countofccname
-
FROM qRenPercRept1
-
Where qRenPercRept1.Merged = "Baltimore"
-
ORDER BY qRenPercRept1.Merged, qRenPercRept1.CountOfccName DESC
-
-
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.
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.
Thank you so much for your help! I did it the first way. Works like a charm.
:)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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, ...
|
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
|
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...
|
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
|
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...
|
by: Rex |
last post by:
Hi
Below is a table with sample data to explain what I want to achieve.
trackID member marker
allele1
------- ------ --------------------------------------------------...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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,...
| |