I am trying to find the last entry for a specific user for each location. I also need to ignore any rows where the balance is zero.
Sample table:
ID location user balance
-- -------- ---- -------
1 GLA A 10.21
2 GLA A 0.00
3 GLA B 45.68
4 GLA B 12.56
5 EDI C 1.23
6 EDI D 5.48
7 EDI D 0.00
8 LON E 78.59
9 MAN F 0.00
10 MAN F 12.98
11 MAN G 56.45
12 MAN G 89.25
13 MAN H 0.00
14 BIR I 0.00
15 BIR I 32.87
Result required:
ID location user balance
-- -------- ---- -------
4 GLA B 12.56
5 EDI C 1.23
8 LON E 78.59
10 MAN F 12.98
12 MAN G 89.25
15 BIR I 32.87
I have been left to cover for a colleague who is off sick and unfotunately my SQL knowledge is limited in comparison.
I have been researching using MAX and PARTITION BY but with no luck so far. This is for a SQL Server 2005 database.
Any assistance with this would be greatly appreciated. I will add any progress I make.
Many Thanks.