473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Totals Group Query

39
Hi

This question should be really easy but I just cant do it!! I have a table below:

Code Group Test Price
56 1 1 2298
56 1 2 1215
56 1 3 1378
56 2 1 492
56 2 2 600

All I want to do is to select the Lowest Price per Group: eg

Code Group Test Price
56 1 2 1215
56 2 1 492

But this seems impossible if I want to include the 'Test' field. So i can get

Code Group Price
56 1 1215
56 2 492

But i wont know what the value of 'Test' is!

Can anyone help?

Thanks
Feb 5 '08 #1
3 1315
Lysander
344 Expert 100+
Hi

This question should be really easy but I just cant do it!! I have a table below:

Code Group Test Price
56 1 1 2298
56 1 2 1215
56 1 3 1378
56 2 1 492
56 2 2 600

All I want to do is to select the Lowest Price per Group: eg

Code Group Test Price
56 1 2 1215
56 2 1 492

But this seems impossible if I want to include the 'Test' field. So i can get

Code Group Price
56 1 1215
56 2 492

But i wont know what the value of 'Test' is!

Can anyone help?

Thanks
You can only do this if there is only 1 lowest price obviously. If this is the case then make 2 queries.

The first I called querytest1
Expand|Select|Wrap|Line Numbers
  1. SELECT TESTTABLE.Code, TESTTABLE.group, Min(TESTTABLE.price) AS MinOfprice
  2. FROM TESTTABLE
  3. GROUP BY TESTTABLE.Code, TESTTABLE.group;
  4.  
Then create a new query based on TESTTABLE and querytest1 and join minofprice to price to get the test field you want, like this
Expand|Select|Wrap|Line Numbers
  1. SELECT TESTTABLE.Code, TESTTABLE.group, TESTTABLE.test, TESTTABLE.price
  2. FROM TESTTABLE INNER JOIN qryTest1 ON (TESTTABLE.price = qryTest1.MinOfprice) AND (TESTTABLE.group = qryTest1.group) AND (TESTTABLE.Code = qryTest1.Code);
  3.  
  4.  
Feb 5 '08 #2
JC2710
39
Thanks Alot!! This seems to work!!

Seems a long way round but I am very grateful for the quick reply!!

Have been struggling with this for ages!!

Cheers
Feb 5 '08 #3
NeoPa
32,556 Expert Mod 16PB
From your test data, I assume you want to group on the Code AND Group fields.
[code]SELECT [code],
[Group],
Mid(Min(Format([Price],'0000000.00') & [Test]),11,99),
Min([Price])
FROM [YourTable]
GROUP BY
Expand|Select|Wrap|Line Numbers
  1. ,
  2.          [Group]
Feb 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: The Bit Bandit | last post by:
Hopefully someone can help me create a query that I'm having some trouble with. I have three tables: invoices, invoicedetails, invoicepayments The fields are: invoices -------- InvoiceNo
8
by: Tony Williams | last post by:
I have a database that hold s figures for each quarter. I want to create a query whereby the user can ask for the running total of the data upto the quarter they enter into a prompt. The database...
2
by: Darren | last post by:
Hi, I am trying to write an Aged Debtors report in MSquery, I have created all of the columns sucessfully, I just need to have totals of each column at the bottom of the report - how can this be...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
3
by: brm6546545 | last post by:
I have a tblTax. It has fields InvoiceNum, TaxAuthority, TaxableTotal, NonTaxableTotal, TaxCollected. Sample data 1,county,10.00,0.00,0.40 1,city,10.00,0.00,0.10 2,state,0.00,15.00,0.15 ...
9
by: MikeSA | last post by:
Hi I a trying to create a chart that reflects monthly cumulative totals from a query. The query fields show sales opportunities forecasted invoice date (OppForInvDate), Opportunity Description and...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
5
by: colin spalding | last post by:
How do I design a totals query that instead of the following result YearOfAcc PremiumGBP 2004 9,142,306.95 2004 1,481,153.21 2005 11,981,987.85 2006 20,653,195.20 2006 ...
7
by: Yesurbius | last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.