此查询中WHERE的顺序错误,但现在是正确的。
postModel = list(PostModel.objects.raw(
SELECT max(pub_date),
count(topic_id) AS freq,
count(DISTINCT author) AS contributors
FROM crudapp_postmodel
WHERE author = "art"
GROUP BY topic_id
ORDER BY pub_date DESC
))
由于
答案 0 :(得分:2)
简单:
SELECT max(pub_date),
count(topic_id) AS freq,
count(DISTINCT author) AS contributors
FROM crudapp_postmodel
WHERE author = "art"
GROUP BY topic_id
ORDER BY pub_date DESC