需要从2个difrent表获取聚合数据。在
Elements
element_type tempcolumn
xyz test1
pqr test2
xyz test3
Users:
User_names
auser
buser
cuser
需要以下格式的输出
^{pr2}$SQL查询示例:
SELECT element_type, count(*)
FROM Elements group by element_type
union
select 'users',count(*) from Users
我们能和django orm一样吗?在
在Django上,您可以使用
|
来连接两个查询集,但这里我不使用它。在因为values/annotate实际上返回元组列表而不是查询集
您可以在Django上运行原始SQL,但raw用于优化。https://docs.djangoproject.com/en/1.9/topics/db/sql/
相关问题 更多 >
编程相关推荐