installer69
Programmer
I have a query that finds the 'max' value of a now() field but how can I find the one before the max?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT A.serial, Max(A.actionDate) AS maxBut1Date
FROM master AS A INNER JOIN [SELECT serial,Max(actionDate) As maxDate FROM master GROUP BY serial] AS B ON A.serial=B.serial
WHERE A.actionDate<B.maxDate
GROUP BY A.serial;
SELECT A.itemfield, Max(A.nowfield) As maxBut1Date FROM theTable A INNER JOIN
(SELECT itemfield, Max(nowfield) As maxDate FROM theTable GROUP BY itemfield) B
ON A.itemfield = B.itemfield
WHERE A.nowfield < B.maxDate
GROUP BY A.itemfield
;
SELECT A.itemfield,Max(A.nowfield) As maxBut1Date FROM theTable A INNER JOIN
(SELECT itemfield,Max(nowfield) As maxDate FROM theTable GROUP BY itemfield) B
ON A.itemfield = B.itemfield
WHERE A.nowfield < B.maxDate
GROUP BY A.itemfield
;