In the end I achieved this by using a function. It probably wouldn't scale to 100's of users very well but still gives me the flexibility I wanted. I'm trying to start an SQLFiddle to demo it but having issues.
Set @CurrentUser = '1' (Jon)
Select User, funcAmountOwed(@currentuser,UserID) from Users
WHERE UserID != @CurrentUser;
Returns:
User | Amount Owed
---------+-------------
Boris | -£15.00
Natalie | £20.00
The function is something along the lines of:
funcAmountOwed(@CurrentUser, @CurrentDebtor);
SET @AmountPaidByCurrentUser = (
Select SUM(Amount) from Bills b
INNER JOIN BillsUsers bu ON b.BillID = bu.BillID_fkey
WHERE b.PaidBy = @CurrentUser and bu.UserId_fkey = @CurrentDebtor)
SET @AmountPaidByDebtor = (
Select SUM(Amount) from Bills b
INNER JOIN BillsUsers bu ON b.BillID = bu.BillID_fkey
WHERE b.PaidBy = @CurrentDebtor and bu.UserId_fkey = @CurrentUser)
RETURN @AmountPaidByCurrentUser - @AmountPaidByDebtor;
I had to nest another function in there to divide the Amount by the Number of people the Bill was split between too but as above I can't remember that from memory without SQLFiddle.