Solved

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

Posted on 2014-04-30
6
279 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:dallagmm
  • 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:dallagmm
ID: 40031680
Jim,

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

Regards,

Dallag
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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:dallagmm
ID: 40156841
Thank you
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 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