是否可以在Django中执行类似的操作:
MyModel.objects.annotate(
val=RawSQL(
"SELECT COUNT(*) FROM another_model_table where some_field= %s",
(a_field_from_MyModel)
)
)
谢谢!
答案 0 :(得分:0)
您可以这样做:
MyModel.objects.annotate(
val=RawSQL(
"""SELECT COUNT(*) FROM another_model_table
where some_field=myapp_mymodel.some_field""",
)
)