473,396 Members | 2,061 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,396 software developers and data experts.

Grouping with detail

Hi,

I'm not really even sure how to phrase this question, so here is a
sample of exactly what I want to do. In the following data set I would
like to select the entry from the group of samples 1 that has the
lowest DOpt. Do the same for the group of samples 2. I would then like
to get the average for the CFU/100ml values of the two samples together
but only for the two values that correspond to the lowest DOpt from
each of the sample sets. Basically I can group based on one field to
determine the record I want to use, but by grouping I loose the detail
of that record. Any suggestions are greatly appreciated.
Location Sample Volume ml Count CFU/100ml DOpt
BL 1 0.1 1 1000 29
BL 1 1 13 1300 17
BL 1 10 75 750 45
BL 2 0.1 2 2000 28
BL 2 1 18 1800 12
BL 2 10 93 930 63

May 18 '06 #1
3 1341
You can use a Union Query for this type of operation

Select * from tbl5 where DOpt In (select min(DOpt) from tbl5 where
sample = 1)
Union All
Select * from tbl5 where DOpt In (select min(DOpt) from tbl5 where
sample = 2)

To get to the Union Query design window - go to Query Design, then go to
the Query Menu/go to Sql Specific/select Union. This will bring up the
union query design window (just a sql window - no grids here). You can
paste the code above. Note: I used a table that I named tbl5 with the
fields that you specified in your post

Location, Sample, Volumn_ml, Count, CFU/100ml, DOpt

and I used your values. The code above will select the entire row for
min(DOpt) for sample 1 and the entire row for min(DOpt) for sample 2 and
will display both rows in the query result when you run the Union Query.
Also, the symbol for a union query in Access is ‡ the infinity symbol
(larger though) in the Database window for the Query Tab.

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
May 18 '06 #2
Thanks Rich,

I have oversimplified my problem somewhat by only including a small
sample of data. The actual data has multiple locations and the sample
number may be common for different locations. Something more like this.

Location Sublocation Date Subtype Sample Volume Count CFU_100ml Dopt
RG R1 5/8/2006 C 1 1 1 100 29
RG R1 5/8/2006 C 1 10 0 0 30
RG R1 5/8/2006 C 1 150 48 32 18
RG R1 5/8/2006 C 2 1 1 100 29
RG R1 5/8/2006 C 2 10 2 20 28
RG R1 5/8/2006 C 2 150 43 28.66666667 13
BL 51E 5/8/2006 A 1 50 0 0 30
BL 51E 5/8/2006 A 1 150 3 2 27
BL 51E 5/8/2006 A 2 50 2 4 28
BL 51E 5/8/2006 A 2 150 6 4 24

So I want the CFU_100ml value for the lowest DOpt in each group where
Location, Sublocation, date, Subtype are unique. I can't select the min
based on sample=1 since sample =1 for multiple locations.

Steve

Rich P wrote:
You can use a Union Query for this type of operation

Select * from tbl5 where DOpt In (select min(DOpt) from tbl5 where
sample = 1)
Union All
Select * from tbl5 where DOpt In (select min(DOpt) from tbl5 where
sample = 2)

To get to the Union Query design window - go to Query Design, then go to
the Query Menu/go to Sql Specific/select Union. This will bring up the
union query design window (just a sql window - no grids here). You can
paste the code above. Note: I used a table that I named tbl5 with the
fields that you specified in your post

Location, Sample, Volumn_ml, Count, CFU/100ml, DOpt

and I used your values. The code above will select the entire row for
min(DOpt) for sample 1 and the entire row for min(DOpt) for sample 2 and
will display both rows in the query result when you run the Union Query.
Also, the symbol for a union query in Access is ‡ the infinity symbol
(larger though) in the Database window for the Query Tab.

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***


May 18 '06 #3
You can use a group by query to narrow down the groupings

Here is what the query would look like

select location, sublocation, cfu_100ml, min(DoPT) from yourTbl Group By
location, sublocation, cfu_100ml

Now you don't even need the union query. Think of group by like
grouping subgroups. The more groups you add, the narrower the spread of
data per grouping.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
May 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: thefirstwml | last post by:
I am using Visual Studio.NET 2002 Professional and am attempting to create a report on Crystal Reports for .NET. I know that Crystal Reports can group on anything, and when I add multiple...
2
by: Debbie Davis | last post by:
Hi there, SQL 2000 I have the following query: SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals GROUP BY sponsor Works great, returns the sponsor and the total * 2 of their...
0
by: Andreas Håkansson | last post by:
I've been using the Muenchian method to group XML data, however I have run into a situation where I am unsure how to solve it. What I need to do is select distinct groups of items. I have an XML...
0
by: Darren | last post by:
I have a report with one level of grouping and a running sum field in the detail section of the report. When I make the running sum field visible, I can see that it increases the count by 1 for...
2
by: Georges Heinesch | last post by:
Hi. I would like to apply some grouping in a report, but I don't know whether this here is possible. Best I describe it with an example: Here some records: Apples green 12 USD...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
0
by: interuser | last post by:
Hi Assume the following columns of a table: StudentId, TestItem, TestDate, Grade I made a report with grouping on studentId. I want in the details section to place a chart that will show the...
0
by: interuser | last post by:
Hi Assume the following columns of a table: StudentId, TestItem, TestDate, Grade I made a report with grouping on studentId. I want in the details section to place a chart that will show the...
2
by: Stephen Witter | last post by:
I am using WriteXml to output data to an xml file, and and XML web control to display it. The code runs fine, however my groups are being ignored. For Instance, the current output is: ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.