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  

min query



 
 
Thread Tools Display Modes
  #1  
Old May 27th, 2010, 10:07 PM posted to microsoft.public.access.queries
Siew-Ming
external usenet poster
 
Posts: 5
Default min query

Hi,

How do I get the 2nd minimum value and the 3rd minimum from a table after I
have done MIN query for the 1st minimum value?

SELECT dbo_CON.SC, dbo_CON.SN, Min(dbo_CON.SQ) AS MinOfSQ
FROM dbo_CON
GROUP BY dbo_CON.SC, dbo_CON.SN
HAVING (((dbo_CON.SC)49));

Thanks,


  #2  
Old May 27th, 2010, 10:26 PM posted to microsoft.public.access.queries
SM
external usenet poster
 
Posts: 38
Default min query

Hi Jerry,

This will give me three different SC SN records. I am looking for same SC
SN records that has next min SQ.

table
SC SN SQ
1 100 1
1 100 2
1 100 3
1 100 4
1 200 2
1 200 3
1 200 4
1 200 5
1 300 1
1 300 3
1 300 4
1 300 5

My expect result from the 1st min query

1 100 1
1 200 2
1 300 1

My expect result from the 2nd min query
1 100 2
1 200 3
1 300 2

My expect result from the 3rd min query
1 100 3
1 200 4
1 300 3


I also need to accomodate two SQ records per SC SN records. What to do no
third SQ rec?


Thanks,
SM

"Jerry Whittle" wrote:

SELECT TOP 3 dbo_CON.SC,
dbo_CON.SN,
Min(dbo_CON.SQ) AS MinOfSQ
FROM dbo_CON
GROUP BY dbo_CON.SC,
dbo_CON.SN
HAVING dbo_CON.SC49
ORDER BY Min(dbo_CON.SQ) ;
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Siew-Ming" wrote:

Hi,

How do I get the 2nd minimum value and the 3rd minimum from a table after I
have done MIN query for the 1st minimum value?

SELECT dbo_CON.SC, dbo_CON.SN, Min(dbo_CON.SQ) AS MinOfSQ
FROM dbo_CON
GROUP BY dbo_CON.SC, dbo_CON.SN
HAVING (((dbo_CON.SC)49));

Thanks,


  #3  
Old May 27th, 2010, 10:42 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default min query

SELECT TOP 3 dbo_CON.SC,
dbo_CON.SN,
Min(dbo_CON.SQ) AS MinOfSQ
FROM dbo_CON
GROUP BY dbo_CON.SC,
dbo_CON.SN
HAVING dbo_CON.SC49
ORDER BY Min(dbo_CON.SQ) ;
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Siew-Ming" wrote:

Hi,

How do I get the 2nd minimum value and the 3rd minimum from a table after I
have done MIN query for the 1st minimum value?

SELECT dbo_CON.SC, dbo_CON.SN, Min(dbo_CON.SQ) AS MinOfSQ
FROM dbo_CON
GROUP BY dbo_CON.SC, dbo_CON.SN
HAVING (((dbo_CON.SC)49));

Thanks,


 




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 10:27 AM.


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