Sqlalchemy - Count Status Is True
I have two tables in db. One is named company, the other named company_map. company table like: C_ID NAME Contact 1 a 12334 2 b 12335 3 c 12336 4 d
Solution 1:
I got idea from SQLAlchemy func.count on boolean column
.having(func.count(case([(company_map.STATUS, 1)])) < func.count(company_map.C_ID))
If your SQLAlchemy is latest version, can use
.having(func.count(1).filter(company_map.STATUS))
which is cleaner than the old.
Post a Comment for "Sqlalchemy - Count Status Is True"