-2

此查询中 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
))

谢谢

4

1 回答 1

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
于 2016-06-20T10:59:33.203 回答