mattdrinks
Technical User
Hi,
I have been on this for a few days now and can not seem to get it working correctly. Any help would be great.
I have a single table and am trying to write some SQL to produce a summary query.
WHAT I HAVE IN THE TABLE
Part Group Range No1 No2 No3
BP1440 BPAD ONE 100 78 50
BP1450 BPAD ONE 100 78 50
BP1460 BPAD ONE 120 90 75
BP1470 BPAD ONE 100 78 50
DI1000 DISC DI2 115 85 60
DI1001 DISC DI2 115 85 60
DI1002 DISC DI2 115 85 60
DI1003 SPEC DI2 200 150 100
DI1004 SPEC DI2 200 150 100
only more records.
WHAT I AM TRYING TO ACHEIVE
Letters Group Range No1 No2 No3
BP BPAD ONE 100 78 50
DI DISC DI2 115 85 60
WHY
This is a summary of the data showing the most popular group, range, No1, No2, and No3 for groups of parts that start with the same letters, so that any new part can be assigned these values when it is added to the database.
WHAT I HAVE SO FAR
I have written a Custom function that returns the first set of letters of a string starting from the left. This bit works and the function is called LEFTLETTERS. I have used this in the following query.
SELECT Count(tblMAMExprod.[Supplier Part]) AS [CountOfSupplier Part], LEFTLETTERS([Supplier Part]) AS Letters, tblMAMExprod.[Product Group], tblMAMExprod.Range, tblMAMExprod.Mkon1, tblMAMExprod.Mkon2, tblMAMExprod.Mkon3
FROM tblMAMExprod
GROUP BY LEFTLETTERS([Supplier Part]), tblMAMExprod.[Product Group], tblMAMExprod.Range, tblMAMExprod.Mkon1, tblMAMExprod.Mkon2, tblMAMExprod.Mkon3;
This produces a row for each unique group with a total of how many parts are in that group, so for the above data it would return:
PartCount Letters Group Range No1 No2 No3
3 BP BPAD ONE 100 78 50
1 BP BPAD ONE 120 90 75
3 DI DISC DI2 115 85 60
2 DI SPEC DI2 200 150 100
WHAT I WOULD LIKE
The query to return just the highest count for each group eg. for above data:
3 BP BPAD ONE 100 78 50
3 DI DISC DI2 115 85 60
I would like to to this with just one query I am sure it is possible with a correlated subquery using TOP 1, but so far when I have tried it Access returns errors such as:
Aggreate function not permitted as part of Sub query
and:
Subquery returns only one row
Does anyone know the SQL that will do this?
I have been on this for a few days now and can not seem to get it working correctly. Any help would be great.
I have a single table and am trying to write some SQL to produce a summary query.
WHAT I HAVE IN THE TABLE
Part Group Range No1 No2 No3
BP1440 BPAD ONE 100 78 50
BP1450 BPAD ONE 100 78 50
BP1460 BPAD ONE 120 90 75
BP1470 BPAD ONE 100 78 50
DI1000 DISC DI2 115 85 60
DI1001 DISC DI2 115 85 60
DI1002 DISC DI2 115 85 60
DI1003 SPEC DI2 200 150 100
DI1004 SPEC DI2 200 150 100
only more records.
WHAT I AM TRYING TO ACHEIVE
Letters Group Range No1 No2 No3
BP BPAD ONE 100 78 50
DI DISC DI2 115 85 60
WHY
This is a summary of the data showing the most popular group, range, No1, No2, and No3 for groups of parts that start with the same letters, so that any new part can be assigned these values when it is added to the database.
WHAT I HAVE SO FAR
I have written a Custom function that returns the first set of letters of a string starting from the left. This bit works and the function is called LEFTLETTERS. I have used this in the following query.
SELECT Count(tblMAMExprod.[Supplier Part]) AS [CountOfSupplier Part], LEFTLETTERS([Supplier Part]) AS Letters, tblMAMExprod.[Product Group], tblMAMExprod.Range, tblMAMExprod.Mkon1, tblMAMExprod.Mkon2, tblMAMExprod.Mkon3
FROM tblMAMExprod
GROUP BY LEFTLETTERS([Supplier Part]), tblMAMExprod.[Product Group], tblMAMExprod.Range, tblMAMExprod.Mkon1, tblMAMExprod.Mkon2, tblMAMExprod.Mkon3;
This produces a row for each unique group with a total of how many parts are in that group, so for the above data it would return:
PartCount Letters Group Range No1 No2 No3
3 BP BPAD ONE 100 78 50
1 BP BPAD ONE 120 90 75
3 DI DISC DI2 115 85 60
2 DI SPEC DI2 200 150 100
WHAT I WOULD LIKE
The query to return just the highest count for each group eg. for above data:
3 BP BPAD ONE 100 78 50
3 DI DISC DI2 115 85 60
I would like to to this with just one query I am sure it is possible with a correlated subquery using TOP 1, but so far when I have tried it Access returns errors such as:
Aggreate function not permitted as part of Sub query
and:
Subquery returns only one row
Does anyone know the SQL that will do this?