Solved

How can I create an Access Query that reads a table column based on other column condtions

Posted on 2014-04-30
6
285 Views
Last Modified: 2014-06-25
I have a table in MS Access that has time related data and I need to select only the pressure at the minimum depth and maximum depth for each well in each time.

Please find the MS Access table attached and I am expecting to have the following results from the query.

Well   Date           Pressure_Min_depth          Pressure_Max_depth
1       1/1/2013                  2333                         46784
1       3/22/2014                 6768                        54654
2       4/1/2014                   2333                        6768
test123.mdb
0
Comment
Question by:Mohammed Dallag
  • 3
  • 2
6 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40031614
Probably a more elegant way of getting this, but define one query as:

SELECT Table1.well, Table1.xdate, Min(Table1.depth) AS MinOfdepth, Max(Table1.depth) AS MaxOfdepth
FROM Table1
GROUP BY Table1.well, Table1.xdate;

Then a second query of:

SELECT qryWellDepths.well, qryWellDepths.xdate, qryWellDepths.MinOfdepth, Table1.pressure, qryWellDepths.MaxOfdepth, Table1_1.pressure
FROM (qryWellDepths INNER JOIN Table1 ON (qryWellDepths.MinOfdepth = Table1.depth) AND (qryWellDepths.well = Table1.well) AND (qryWellDepths.xdate = Table1.xdate)) INNER JOIN Table1 AS Table1_1 ON (qryWellDepths.MaxOfdepth = Table1_1.depth) AND (qryWellDepths.xdate = Table1_1.xdate) AND (qryWellDepths.well = Table1_1.well);

Jim.
0
 
LVL 57
ID: 40031617
Here's the DB by the way..

Jim.
test123.mdb
0
 

Author Comment

by:Mohammed Dallag
ID: 40031680
Jim,

I need the pressure at the max depth and min depth not the depth.

Regards,

Dallag
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 57
ID: 40031722
That's what I gave you.  For each well, for each day, the min depth, pressure at that depth, and the max depth and the pressure at that depth.

Jim.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40031896
try this query


Select T.well,T.xdate As [Date], Min(T.Pressure) as Pressure_Min_depth,  Max(T.Pressure) as Pressure_Max_depth
From
(
SELECT A.Well, A.xdate, A.MinOfdepth AS Depth, B.Pressure
FROM (SELECT Table1.well, Table1.xdate, Min(Table1.depth) AS MinOfdepth
FROM Table1
GROUP BY Table1.well, Table1.xdate
UNION ALL
SELECT Table1.well, Table1.xdate, Max(Table1.depth) AS MinOfdepth
FROM Table1
GROUP BY Table1.well, Table1.xdate
Order By 1,2,3
)  AS A INNER JOIN Table1 AS B ON (A.Well = B.Well) AND (A.xDate = B.xDate) AND (A.MinOfdepth = B.Depth)
ORDER BY A.Well, A.xdate, A.MinOfdepth, B.Pressure
) As T
Group By  T.well,T.xdate
0
 

Author Closing Comment

by:Mohammed Dallag
ID: 40156841
Thank you
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question