正在尝试将此mssql查询转换为djang

2024-04-16 16:10:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试转换此查询

SELECT coalesce(SUM( PortFixedIncApp.PrincipalBalance + (PortFixedIncApp.PrincipalBalance * PortFixedIncApp.DailyInterestrate * DATEDIFF(day, PortFixedIncApp.LastDateOfInterestAccruals,'2016-02-05')) + PortFixedIncApp.InterestBalance),0 ) AS MarketValue
FROM PortFixedIncApp
WHERE (PortFixedIncApp.TransStatus = 'Active')
    AND PortFixedIncApp.AccountNo='3051010000401'
    AND (PortFixedIncApp.EndDate <='2016-02-05')

这就是我在django试图做的

Portfixedincapp.objects.filter(Q(transstatus="Active")&
                                Q(accountno="{0}".format(custaccountno))&
                                Q(enddate__lte=today)).aggregate(market_value=\
                                Coalesce(Sum(F("principalbalance")+(F("principalbalance") * F("dailyinterestrate") * arrow.get(F("lastdateofinterestaccruals")).date() - today) + F("interestbalance"),
                                output_field=models.IntegerField()),0))

我在运行时遇到此错误

can't parse single argument type of '<class 'django.db.models.expressions.F'>'

Tags: anddjangotodaymodelsselectactivesumday