All pastes #839254 Raw Edit

Someone

public text v1 · immutable
#839254 ·published 2007-12-30 22:53 UTC
rendered paste body
+-----+------------+--------+--------+------------+
| id  | account_id | amount | status | date       |
+-----+------------+--------+--------+------------+
| 164 |        764 |  10.00 |      0 | 2007-12-30 |
| 165 |        764 |  10.00 |      0 | 2007-12-30 |
| 166 |        764 |  10.00 |      0 | 2007-12-30 |
| 167 |        764 |  10.00 |      0 | 2007-12-30 |
| 168 |        764 |  10.00 |      0 | 2007-12-30 |
| 169 |        764 |  10.00 |      1 | 2007-12-30 |
| 170 |        764 |  10.00 |      0 | 2007-12-30 |
| 171 |        764 |  10.00 |      0 | 2007-12-30 |
| 172 |        764 |  10.00 |      0 | 2007-12-30 |
| 173 |        764 |  10.00 |      0 | 2007-12-30 |
| 174 |        764 |  10.00 |      0 | 2007-12-30 |
| 175 |        764 |  10.00 |      1 | 2007-12-30 |
| 176 |        764 |  10.00 |      0 | 2007-12-30 | // we want this id, date
| 177 |        764 |  10.00 |      0 | 2007-12-30 |
| 178 |        764 |  10.00 |      0 | 2007-12-30 |
| 179 |        764 |  10.00 |      0 | 2007-12-30 |
| 180 |        764 |  10.00 |      0 | 2007-12-30 |
| 181 |        764 |  10.00 |      0 | 2007-12-30 |
| 182 |        764 |  10.00 |      0 | 2007-12-30 | // we want this amount
+-----+------------+--------+--------+------------+
19 rows in set (0.00 sec)

Now out of a result set like this, I want the MINIMUM id, AFTER THE MAXIMUM id LAST with status of 1.

So in this case, the result set date row I would want returned would be from ROW ID 176 and 182, anyone have any suggestions?

i.e. in psuedo, overall result set: (LATEST TRANSACTION AMOUNT), (EARLIEST FAILED TRANSACTION DATE), (DATEDIFF(CURDATE(), EARLIEST FAILED TRANSACTION DATE)