Solved

How can make MS Access Query that read a table column based on conidtion

Posted on 2014-04-02
4
441 Views
Last Modified: 2014-04-22
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 follwing results from the query.

Well   Date       Depth   Pressure
1     1/1/2013     23        2333
1     1/1/2013    666       46784
1     3/22/2014    2         6768
1     3/22/2014  777       54654
2     4/1/2014    11         2333
2     4/1/2014    888       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
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39972227
You would start out with an aggregate query:

qryWellDates:
SELECT Well, [Date] as PressDate, Min([Depth]) as MinDepth, Max([Depth]) as MaxDepth
FROM yourTable
GROUP BY Well, [Date]

Then, you would join this to your table to get the pressure for those Well/Date combinations

SELECT qryWellDates.Well, qryWellDates.PressDate, qryWellDates.MinDepth as Depth,
             yourTable.Pressure
FROM qryWellDates
INNER JOIN yourTable
ON qryWellDates.Well = yourTable.Well
AND qryWellDates.PressDate = yourTable.[Date]
AND qryWellDates.MinDepth = yourTable.[Depth]
UNION ALL
SELECT qryWellDates.Well, qryWellDates.PressDate, qryWellDates.MaxDepth as Depth,
             yourTable.Pressure
FROM qryWellDates
INNER JOIN yourTable
ON qryWellDates.Well = yourTable.Well
AND qryWellDates.PressDate = yourTable.[Date]
AND qryWellDates.MaxDepth = yourTable.[Depth]
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39972301
try this query


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;



see query1 on your sample db
test123.mdb
0
 

Author Closing Comment

by:Mohammed Dallag
ID: 39997164
very good
0
 

Author Comment

by:Mohammed Dallag
ID: 40016256
I need to change the output of the MS Query to be like the attached file
4-22-2014-12-26-08-PM.jpg
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

621 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