try:
for i in text:
cur.execute(sql, [(i),])
result = cur.fetchone()
if result is not None:
print('Найдено')
else:
print('Не найдено')
except TypeError as err:
print('Ошибка:', err)
else:
print('Готово')
SELECT Code.name,
Plan.value AS 'plan',
Fact.value AS 'fact'
FROM Code
LEFT JOIN (SELECT codes,
SUM(value) AS 'value'
FROM Income_Plan
GROUP BY codes) plan
ON plan.codes = Code.id
LEFT JOIN (SELECT codes,
SUM(value) AS 'value'
FROM Income_Fact
GROUP BY codes) fact
ON fact.codes = Code.id
union_sq = q1.union_all(q2).subquery()
q = session.query(func.sum(union_sq.c.plan),
func.sum(union_sq.c.fact),
Code.name).select_entity_from(union_sq).group_by(Code.id)
union_sq = union_all(q1, q2).subquery()
q = session.query(union_sq.c.plan, union_sq.c.fact, Code.name).select_entity_from(union_sq).group_by(Code.id)
q1 = session.query(func.sum(Income_Plan.value).label('plan'),
Code.name,
literal_column('0').label('fact')).group_by(Code.id)
q2 = session.query(literal_column(0).label('plan'),
Code.name,
func.sum(Income_Fact.value).label('fact')).group_by(Code.id)
q1.union_all(q2)
SELECT *
FROM Users
WHERE user_id = 1 OR user_id = 2
Users.query.filter(or_(User.user_id ==1, User.user_id ==2))
User.query.filter(or_(User.id == a, a == None) <...>