开发者

SQLAlchemy using Execute

开发者 https://www.devze.com 2023-03-18 08:50 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号