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  

Append Query with Oldest top Records by Group



 
 
Thread Tools Display Modes
  #1  
Old April 20th, 2010, 01:13 AM posted to microsoft.public.access.queries
Aaron
external usenet poster
 
Posts: 242
Default Append Query with Oldest top Records by Group

Hello All,

I am not sure where even to began to start on this query.

I am looking for a query that on table tblmaxdata that has the following
fields (PN, QTY, CYCDATE, ABCCLASS) The ABCCLASS has values of A, B, C. I
am looking to get 20 oldest date (CYCDATE) records that have the value of "A"
in ABCCLASS, plus the top 10 Oldest date (CYCDATE) records that have "B" in
ABCCLASS, plus the top 10 Oldest date (CYCDATE) records that have "C" in
ABCCLASS.

Is this possible and if so how would I even begin to create this?

Thanks in advance for any help on this headache query. lol

Thanks,
Aaron
  #2  
Old April 20th, 2010, 01:44 AM posted to microsoft.public.access.queries
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default Append Query with Oldest top Records by Group

Three top values queries unioned together should do it. Something like...

SELECT TOP 20 PN, Qty, CYCDate, ABCClass
FROM tblMaxData
WHERE ABCClass = 'A'
ORDER BY CYCDate ASC
UNION
SELECT TOP 10 PN, Qty, CYCDate, ABCClass
FROM tblMaxData
WHERE ABCClass = 'B'
ORDER BY CYCDate ASC
UNION
SELECT TOP 10 PN, Qty, CYCDate, ABCClass
FROM tblMaxData
WHERE ABCClass = 'B'
ORDER BY CYCDate ASC;

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201004/1

  #3  
Old April 20th, 2010, 01:46 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Append Query with Oldest top Records by Group

On Mon, 19 Apr 2010 17:13:01 -0700, Aaron
wrote:

Hello All,

I am not sure where even to began to start on this query.

I am looking for a query that on table tblmaxdata that has the following
fields (PN, QTY, CYCDATE, ABCCLASS) The ABCCLASS has values of A, B, C. I
am looking to get 20 oldest date (CYCDATE) records that have the value of "A"
in ABCCLASS, plus the top 10 Oldest date (CYCDATE) records that have "B" in
ABCCLASS, plus the top 10 Oldest date (CYCDATE) records that have "C" in
ABCCLASS.

Is this possible and if so how would I even begin to create this?

Thanks in advance for any help on this headache query. lol

Thanks,
Aaron


Do you in fact want an *append* query to store this data redundantly in a
second table?

I'd use a UNION query instead to dynamically get the oldest records as of the
time you run the query:

SELECT TOP 20 PN, QTY, CYCDATE, ABCCLASS
FROM tblMaxdate
WHERE ABCCLASS = "A"
ORDER BY CYCDATE DESC
UNION ALL
SELECT TOP 10 PN, QTY, CYCDATE, ABCCLASS
FROM tblMaxdate
WHERE ABCCLASS = "B"
ORDER BY CYCDATE DESC
UNION ALL
SELECT TOP 10 PN, QTY, CYCDATE, ABCCLASS
FROM tblMaxdate
WHERE ABCCLASS = "C"
ORDER BY CYCDATE DESC;

--

John W. Vinson [MVP]
 




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 03:36 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.