-2

The order of the WHERE in this query was wrong, but it is correct now.

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
))

Thanks

Shane G
  • 3,129
  • 10
  • 43
  • 85
  • 1
    the WHERE comes after the table name – e4c5 Jun 17 '16 at 13:43
  • 1
    You should really read the documentation on creating SQL queries before asking for help, but this should work: `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` – solarissmoke Jun 17 '16 at 13:43

1 Answers1

2

Simple:

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
Shane G
  • 3,129
  • 10
  • 43
  • 85
Hamed Rostami
  • 1,670
  • 14
  • 16