我正在尝试将以下内容翻译为sqlalchemy:
SELECT COUNT(TableA.id) AS 'number_of_staff'
FROM TableA
WHERE datediff(month, TableA.Date, getDate()) >= 0
AND lookup_TableB = '4'
AND (TableA.End_Date IS NULL OR TableA.End_Date = '')
到目前为止,我已经:
get_tablea_number = self.db_session.query(func.count(TableA.id)).\
filter(TableA.lookup_TableB == property_id,
todays_date.month - extract('month', TableA.date) >= 0,
or_(TableA.end_date == None,
TableA.end_date == '')).scalar()
然而,它输出与上面的SQL查询不同的值,我认为这是由于 todays_date.month - extract('month', TableA.date) >= 0
导致的(其中 todays_date.month
只是一个日期时间对象)。