Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-04-02
4
Medium Priority
?
449 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 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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