Find max and min number in group

alwazeer

Registered User.
Local time
Today, 03:17
Joined
Nov 9, 2011
Messages
36
hi all
what i need is:
show the great value for each group

max2 in group3 must be 2 not 5
her is a pic and db
 

Attachments

  • MinMaxTest.mdb
    MinMaxTest.mdb
    232 KB · Views: 150
  • x1.JPG
    x1.JPG
    18.9 KB · Views: 144
max2 in group3 must be 2 not 5

How do you figure?

Look at just the table, filter to Rg1=3. The largest value in the Rg1 column is 3. Please explain how you expect 5 to be returned.

I suspect you want to define a new grouping which would require a whole new query.
 
here is what i have:

SELECT TestTbl.Rg2, Min(TestTbl.Ltnum) AS MinOfLtnum, Max(TestTbl.Ltnum) AS MaxOfLtnum1, (SELECT TOP 1 T1.RG1 FROM TestTbl AS T1 WHERE T1.Rg2=TestTbl.Rg2 ORDER BY T1.ID DESC, T1.LTNUM DESC) AS Max2
FROM TestTbl
GROUP BY TestTbl.Rg2;
 
here's the final:

SELECT TestTbl.Rg2, Min(TestTbl.Ltnum) AS MinOfLtnum, Max(TestTbl.Ltnum) AS MaxOfLtnum1, (SELECT TOP 1 T1.RG1 FROM TestTbl AS T1 WHERE T1.Rg2=TestTbl.Rg2 ORDER BY T1.LTNUM & T1.RG1 DESC) AS Max2
FROM TestTbl
GROUP BY TestTbl.Rg2;
 
Youre welcone sir. I forgot to add ti the query the 2min. You only follow what i dit and instead if sortin it Desc sort it Asc, ascending
 

Users who are viewing this thread

Back
Top Bottom