我正在使用postgresql
如果我删除a.school不在,它运作良好
cursor.execute('create temp table paso as(SELECT b.username as user__username ,count(a.name) as tot FROM principal_student a join users_user b ON a.user_id = b.id join principal_cycle c ON c.id = a.cycle_id
WHERE a.school not in ("student not It has school age","You do not have school age") AND (c.status=true) group by a.name,b.username order by b.username)');
cursor.execute('Select a.user__username,count(a.tot) from paso a group by user__username order by total desc')
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns,row)))
context['prod'] = results
cursor.close()