[英]Using filter_by does not work as expected
I am trying to get the count of categories in item_name using this script below 我试图使用下面的脚本获取item_name中的类别计数
db.session.query(func.count(Garden.id).label('count'),Garden.item_name).group_by(Garden.item_name).all()
Works like a charm, but I need to filter this by specifying another condition, which I am not able to get it right. 像魅力一样工作,但我需要通过指定另一个条件来过滤它,这是我无法做到的。 But I tried this script below.
但我在下面尝试了这个脚本。
db.session.query(func.count(Garden.id).label('count'),Garden.item_name).group_by(Garden.item_name).filter_by(Garden.item_type='vegetable').all()
i am trying to include item_type specific condition. 我想包括item_type特定条件。 But, I am making some mistake that I get an error.
但是,我犯了一些错误,我得到了一个错误。 I am also aware its not how we add filter and group by at the same time.
我也知道它不是我们如何同时添加过滤器和组。 Can anyone post your solution?
有人可以发布您的解决方案
Thanks 谢谢
好的,我解决了。
db.session.query(func.count(Garden.id).label('count'),Garden.item_name).filter(Garden.item_type=="vegetable").group_by(Garden.item_name).all()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.