Hi,
I want to get the remaining/latest balance of the cardnumber from the rows. Below is the sample of the table.
trans_id | cardnumber | trans_date | balance
---------------------------------------------------------------
1 | 1000005240000008 | 2009-07-03 04:54:27 | 88
2 | 1000005120000008 | 2009-07-04 05:00:07 | 2
3 | 1000005110000008 | 2009-07-05 13:18:39 | 3
4 | 1000005110000008 | 2009-07-06 13:18:39 | 4
5 | 1000005110000008 | 2009-07-07 14:25:32 | 4.5
6 | 1000005120000002 | 2009-07-08 16:50:51 | -1
7 | 1000005240000002 | 2009-07-09 17:03:17 | 1
The result should look like this:
trans_id | cardnumber | trans_date | balance
---------------------------------------------------------------
1 | 1000005110000008 | 2009-07-07 14:25:32 | 4.5
2 | 1000005120000002 | 2009-07-08 16:50:51 | -1
3 | 1000005240000002 | 2009-07-09 17:03:17 | 1
I already have a query but it goes something like this:
SELECT cardnumber, MAX(balance), trans_date
FROM transactions
GROUP BY cardnumber
I really need help on this, im having a hard time. :( Thanks in advance.
Mark