?
Solved

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

Posted on 2014-04-30
6
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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 58
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 58
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

765 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