Skip to content
Advertisement

Convert PostgreSQL COUNT … FILTER query to SQL Alchemy

I’m new to SQLAlchemy, and I would like to convert this PostgreSQL query:

I have already tried this:

Thank you in advance for your help

Advertisement

Answer

Thanks to @IljaEverilä’s comment, here is a more direct answer:


(Original answer)

I’m not sure if SQLAlchemy’s postgresql dialect specifically handles COUNT … FILTER, but you can accomplish the same thing using SUM and CASE:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement