小编Pan*_*uel的帖子

Django raw()查询,WHERE子句中的计算字段

我想知道在使用计算字段时是否对raw()方法的语法有任何限制.这是一个简单的例子:

Company.objects.raw('''SELECT *,core_location.a + core_location.b as dist
FROM core_location,core_company  
ORDER BY dist''')
Run Code Online (Sandbox Code Playgroud)

上面的代码按预期工作(结果按计算字段'dist'排序),但是当我添加WHERE子句时,例如:

Company.objects.raw('''SELECT *,core_location.a + core_location.b as dist
FROM core_location,core_company
WHERE dist<10  
ORDER BY dist''')
Run Code Online (Sandbox Code Playgroud)

我得到了(1054,'where where'中的"未知栏'dist'")

到目前为止看起来我不能在WHERE子句中使用计算字段,但我可以在ORDER BY语句中使用它.请分享您的经验.谢谢.

mysql django mysql-error-1054

1
推荐指数
1
解决办法
2403
查看次数

标签 统计

django ×1

mysql ×1

mysql-error-1054 ×1