I am trying to write a query to use that will accomplish the task of subtracting pH values from a database based on the year that the record has associated with it. I work for an agricultural company and we are working with soil sampled data. A field may have its soil sampled every 1-5 years, for example, and therefore a query just saying subtract 2018 from 2021 values won't work because we don't know which year was the last time. Therefore, I am trying to write a query that access the first time a field had a sample taken, and then subtracting that from the most recent sample that was taken for it. This could end up with one field having a change of just 2 years between samples while another has 9. To reiterate and simplify as much as possible: I want to subtract two values that will be in the same column (Soil_PH) based on their value in the GrowingYear column. I will attach a CSV of the type of data that I am working with. Additionally, I will attach the query I currently use to pull in data for a specific year, or I can alter it a bit to pull in all records from a few years. Attachments: Lab Data Query.txt PH2020 2.csv
|