Database:
ACCOUNT | LIMIT | MARKET | LENDING | BALANCE
----------------------------------------------
1000010 | 200.00 | 0.00 | -234.55 | 1000.00
1000010 | 300.00 | 11.00 | 0.00 | -239.00
1000010 | -200.00 | 235.00 | -134.00 | 450.00
1000011 | 30.00 | 1.00 | -10.00 | -98.00
1000011 | -200.00 | 235.00 | -134.00 | 49.00
SQL statements:
SUM(LIMIT) as bond_limit,
SUM(MARKET) as market_value,
SUM(LENDING) as lending_value,
SUM(case when BALANCE > 0 then BALANCE else 0 end) as FREE,
SUM(case when BALANCE < 0 then BALANCE else 0 end) as MISS
This should be the result:
ACCOUNT | LIMIT | MARKET | LENDING | BOND_LIMIT | MARKET_VALUE | LENDING_VALUE | FREE | MINUS
1000010 | 200.00 | 0.00 | -234.55 | Sum(LIMIT) | Sum(MARKET) | Sum(LENDING) | Sum(BALANCE) or 0
1000010 | 300.00 | 11.00 | 0.00 | Sum(LIMIT) | Sum(MARKET) | Sum(LENDING) | Sum(BALANCE) or 0
1000010 | -200.00 | 235.00 | -134.00 | Sum(LIMIT) | Sum(MARKET) | Sum(LENDING) | Sum(BALANCE) or 0
1000011 | 30.00 | 1.00 | -10.00 | Sum(LIMIT) | Sum(MARKET) | Sum(LENDING) | Sum(BALANCE) or 0
1000011 | -200.00 | 235.00 | -134.00 | Sum(LIMIT) | Sum(MARKET) | Sum(LENDING) | Sum(BALANCE) or 0
erg = database.objects.filter(
account=ACCOUNT
).aggregate(
bond_limit=Sum('LIMIT'),
market_value=Sum('MARKET'),
lending_value=Sum('LENDING')
)
.filter(bond_number=bond_number).aggregate(bond_limit=Sum('LIMIT')
^^^^^^^^^^^
NameError: name 'bond_number' is not defined
erg.filter(BALANCE__gt=0)...
0 comments:
Post a Comment
Thanks