Vba*_*Beg 1 django django-models
我想使用djagno模型执行此类查询:
SELECT id, ( first+second+third ) FROM testTable
Run Code Online (Sandbox Code Playgroud)
没有分组.试图使用谷歌找到解决方案,但没有成功.
提前致谢,
使用F()和annotate():
from django.db.models import F
# the sum of the three columns `first`, `second` and `third` will be
# accessible as `.my_sum`
results = my_model.objects.annotate(
my_sum=F('first') + F('second') + F('third'),
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |