473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

access query to show min max for overlapping intervals

1
i need an access query to combine the lithologies to only have one dpeth from and to for each interval. should look like this
ID Bore Depth1 Depth2 Lithology
96 DDH_1 0 14.48 OOO
100 DDH_1 14.48 22.56 USE
103 DDH_1 22.56 25.6 WOO
105 DDH_1 25.6 30.18 USE
106 DDH_1 30.18 34.75 UOO

with min max querry the USE will go from 14.8 to 30.18 overlapping with the WOO type

but currently looks like this

ID Bore Depth1 Depth2 Lithology
96 DDH_1 0 3.05 OOO
97 DDH_1 3.05 8.94 UOO
98 DDH_1 8.94 12.34 UOO
99 DDH_1 12.34 14.48 UOO
100 DDH_1 14.48 14.71 USE
101 DDH_1 14.71 20.27 USE
102 DDH_1 20.27 22.56 USE
103 DDH_1 22.56 23.47 WOO
104 DDH_1 23.47 25.6 WOO
105 DDH_1 25.6 30.18 USE
106 DDH_1 30.18 32.61 UOO
107 DDH_1 32.61 34.75 UOO
108 DDH_1 34.75 36.78 USE
109 DDH_1 36.78 39.62 USE
110 DDH_1 39.62 40.69 USE
111 DDH_1 40.69 46.02 USE
112 DDH_1 46.02 51.51 USE
113 DDH_1 51.51 60.66 USE
114 DDH_1 60.66 64.62 USE
115 DDH_1 64.62 67.67 USE
116 DDH_1 67.82 89.05 USE
117 DDH_1 89.05 90.07 VQO
118 DDH_1 90.07 92.66 USE
119 DDH_1 92.66 98.02 USE
120 DDH_1 98.02 98.83 USE
121 DDH_1 98.83 99.82 USE
122 DDH_1 99.82 114.6 UAO
123 DDH_1 114.6 121.23 UAO
124 DDH_1 121.23 130.15 UAO
125 DDH_1 130.15 133.86 USAO
126 DDH_1 133.86 152.53 UAO
127 DDH_1 152.53 154.69 UAO
128 DDH_1 154.69 160.32 UAO
129 DDH_1 160.32 163.37 UAO
130 DDH_1 163.37 192.18 UAO
131 DDH_1 192.18 193.7 UAO
132 DDH_1 193.7 230.12 UAO

thnaks
Mar 2 '12 #1
5 1944
TheSmileyCoder
2,322 Expert Mod 2GB
Its very nice that you provide detailed sample data. However I have no easy way of getting this into access and work on it.

If you export your table as a csv file and attach the csv file here, I would be willing to take a look at it. It should be doable I think.
Mar 2 '12 #2
patjones
931 Expert 512MB
Basically, you need consecutive records for a lithology to collapse down to one line? So, ID's 108 through 116 would become 108 DDH_1 34.75 89.05 USE?

I pasted the data into a text file then imported into Excel, saved as an .XLS 2003 file - attached here.

Pat
Attached Files
File Type: xls group_lithos.xls (19.5 KB, 395 views)
Mar 2 '12 #3
Mihail
759 512MB
I don't understand how should be arranged your data ?
Use patjones's xls to arrange data as you need to be.

I am sure that can be done either in Access either in Excel, but I can't understand what you wish to achieve.
Mar 3 '12 #4
patjones
931 Expert 512MB
I think I understand what you need, and I have a SQL query that gets us part of the way there. I'm going to look at it some more later today.
Mar 3 '12 #5
patjones
931 Expert 512MB
Hi,

Sorry for the delay, as I've been able to think about this only here and there for a little bit. Maybe you have found a solution, but I want to post what I came up with so that maybe we can get the discussion going again.

The SQL shown below accomplishes what you want, except that it leaves off the beginning and ending ID's (so in your sample data, 96 and 126 are left out). I need to think a little more about modifying it to include the endpoints.

Expand|Select|Wrap|Line Numbers
  1. SELECT tC.ID, tC.Bore, tC.Depth1, tD.max_Depth2, tC.Lithology
  2. FROM (SELECT tA.ID, tA.Bore, tA.Depth1, tA.Lithology
  3.       FROM group_lithos AS tA, group_lithos AS tB
  4.       WHERE tA.Lithology <> tB.Lithology AND (tB.ID = tA.ID - 1)) AS tC INNER JOIN (SELECT tA.ID AS lower_ID, MIN(tB.Depth1) AS max_Depth2
  5.                                                                                     FROM group_lithos AS tA, group_lithos AS tB       
  6.                                                                                     WHERE tA.Lithology <> tB.Lithology AND tB.ID > tA.ID
  7.                                                                                     GROUP BY tA.ID) AS tD ON tC.ID = tD.lower_ID;
  8.  


There are two sub-queries here. The first one, denoted by "tC", picks out the lowest ID for each contiguous lithology grouping, while the second one, denoted by "tD", gets the highest Depth2. JOINing them together yields the records that you're looking for.

I have a strong suspicion that there's a more concise solution, which I want to keep looking for. This is an interesting problem.
Mar 9 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rob Richardson | last post by:
Greetings! I am rewriting a VB6 application in VB .Net. The database (which was converted from Access 97 into Access 2000) has two nearly identical queries. One, called GetNewOrderNumber, is: ...
5
by: Art | last post by:
Hi, Can anyone point me to an example of how I would execute a query I've created in an Access DB. I've copied the SQL down to my VB.net application and that works fine, but it's ugly. I'd like...
4
by: ShastriX | last post by:
Getting a weird error while trying out a query from Access 2003 on a SQL Server 2005 table. Want to compute the amount of leave taken by an emp during the year. Since an emp might be off for...
5
by: redstamp | last post by:
Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field. To explain, I have a table of...
12
by: zwasdl | last post by:
Hi, I'm using MS Access to query against Oracle DB via ODBC. Is it possible to use HINT in Access? Thanks, Wei
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
1
by: natalieo | last post by:
Hi everyone , Hope all is well with you guys and girls :) I saw someone had a similar posting in this forum and need some help also with a Access Query Expression. I need an expression to...
3
by: cloh | last post by:
I have a pre-written Access query and one of the resulting columns is listed in this format: A B C A B C A B
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
5
by: rushtona | last post by:
I'm trying to build an Access Query that will give me the year and the total catch, even if there was no catch. The problem is if there was no catch for a certain year the query is not showing that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.