0
쿼리에서 고급 계산을 수행 할 수 있는지 궁금합니다.Django 쿼리 그룹 계산
여기에 데이터가 잘 표시되고 합계 (credit) - 합계 (차변) 인 이익을 추가하고 싶습니다.
내 오류 : 합계 ('신용')를 계산할 수 없습니다 : '신용 것은'총
trd = Trades.objects.all().filter (acct_id = acct.id)
.values ('issue')
.annotate (
cnt = Count ('issue'),
debit = Sum ('debit'),
credit = Sum ('credit'),
shrs = Sum ('shares'),
profit = Sum ('credit') - Sum ('debit')
)
.order_by ('issue')
감사합니다.
strange, profit = Sum ('credit'- 'debit')이 오류를 제공합니다 : 지원되지 않는 피연산자 유형이 - : 'str'및 'str'입니다. +로 변경하면 다른 오류가 발생합니다. – diogenes
또 다른 아이디어는 ... aggregate() 함수를 살펴보십시오 : https://stackoverflow.com/questions/8616343/django-calculate-the-sum-of-the-column-values-through-query. 나는 그것이 당신이 찾고있는 것에 더 가깝다고 생각합니다. – ravioli
한 번 더 : https://stackoverflow.com/questions/12165636/django-aggregation-summation-of-multiplication-of-two-fields – ravioli