I'm trying to work with nested subqueries in MySQL and I'm getting pretty confused.
To keep it simple, I have a table with a datetime field, temperature and pressure.
It looks like this:
ob, temp, pres
2005-04-01 14:00:00, 27.000, 1004.00
... lots more rows like this
Here's the problem. I want to make a query that will give me the ob, temp, pres AND the ob, temp, pres of 12 hours previous. I want this to be returned as one row.
The reason for this is to calculate sea-level pressure from station pressure, which means I have to have the temperature and station pressure 12 hours prior to whatever datetime I'm working with and bla bla bla. If I can just get this query down pat I'll have it made.
Any advice on how to build such a subquery of a subquery?
In essence, I want:
SELECT ob, temp, pres, ob12, temp12, pres12
FROM (SELECT ob-12 hours ago as ob12, temp minus 12 hours as temp12, pres minus 12 hours as pres12) as query
The above is the basic logic of what I want to do, but how do I make it happen?