Hi,

I have a problem to convert the following MySQL query into SQLAlchemy 
(python) expression:

SELECT 
    SUM(IF(t1.column_3 = 1
            AND t1.column_4 > DATE_SUB(NOW(), INTERVAL 2 MONTH),
        1,
        0)) AS label_1,
    SUM(IF(t1.column_3 = 1
            AND t1.column_4 > DATE_SUB(NOW(), INTERVAL 2 MONTH),
        1,
        0)) / COUNT(*) * 100 AS label_2
FROM
    table_1 t1
        JOIN
    table_t2 t2 ON t2.column1 = t1.column1
        JOIN
    table_t3 t3 ON t3.column1 = t2.column2
WHERE
    t3.end_datetime > NOW();

Versions:
Python 2.7
MySQL 5.7.18

SQLAlchemy 1.0.12
MySQL-python 1.2.5


Does anyone know how I can do that?

Best,
Nemanja

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to