I have the following table called 'ArchiveTable':
+---------+-----------------+---------+-----------------+--------------+------------------+ | maxtemp | maxtemptime | mintemp | mintemptime | minwindchill | minwindchilltime | +---------+-----------------+---------+-----------------+--------------+------------------+ | 27.9 | 3/17/2015 16:55 | 25.8 | 3/17/2015 19:00 | 25.8 | 3/17/2015 19:00 | +---------+-----------------+---------+-----------------+--------------+------------------+ | 25.7 | 3/17/2015 19:05 | 19.3 | 3/18/2015 9:05 | 19.3 | 3/18/2015 9:05 | +---------+-----------------+---------+-----------------+--------------+------------------+ | 23.1 | 3/18/2015 19:05 | 18.7 | 3/19/2015 6:30 | 18.7 | 3/19/2015 6:30 | +---------+-----------------+---------+-----------------+--------------+------------------+
I have to select the maximum value of 'maxtemp' and its corresponding 'maxtemptime' date, minimum value of 'mintemp' and its corresponding date, and minimum value of 'minwindchill' and its corresponding date.
I know how to obtain the max and min values with the MAX()
and MIN()
functions, but I cannot associate these values to the corresponding date.
If you could take the values on separate rows, then you could do something like this:
Otherwise, if you can do something like this:
The
limit 1
is because multiple rows might have the same values. If so, you can arbitrarily choose one of them, based on how your question is phrased.