SQLAlchemy using Execute
I am having a hard time using group by, having, and sum all together in a manual query. Below is my query, can someone help me identify why it returns so many rows (as if it isn't applying the group by or having).
q = meta.Session.execute('SELECT ID FROM table GROUP BY ID HAVING SUM(viewCount)= 0')
results = q.fetchall()
len(res开发者_如何学运维ults)
Output from the above is 371
If I run the query
SELECT ID FROM table GROUP BY ID HAVING SUM(viewCount)=0;
Output from regular SQL is 17 rows found
I tried utilizing the group_by that SQLAlchemy offers but I couldn't get it to work right with the having and the sum. I saw that I may need to include the func sum. Any help is much appreciated.
精彩评论