I am new to Flask SQl alchemy; Though i understand that alchemy abstracts the sql syntax and makes things easy while creating models; there could be times when we want to visualize data in the front end in a very specific way.
I have the following query which i would like to use using alchemy using session.query and filter and possibly grouping.
My query reads:
- mysql>
SELECT status, COUNT(id) FROM bar_baz where not name = 'Foo' and not name = 'Bar' GROUP BY status
select (select COUNT(id) FROM instance where not name = 'erf' and not tiername = 'wer' and type='app') as app, (select COUNT(1) FROM instance_2 where not name = 'visq' and not name = 'werf' and type='adc') as adc from dual;
I verified that the following queries works with the MySQL; I was wondering if we have a function similar to
c = conn.cursor()
query = 'SELECT status, COUNT(id) FROM bar_baz where not name = 'Foo' and not name = 'Bar' GROUP BY status'
c.execute(query)
print c.fetchall()
class Instance(Base):
__tablename__ = 'instance'
id = Column(Integer, primary_key=True)
name = Column(String)
status = Column(String)
type = Column(String)
class Instance2(Base):
__tablename__ = 'instance_2'
id = Column(Integer, primary_key=True)
name = Column(String)
status = Column(String)
type = Column(String)
inc = Column(Integer)
The query of Interest:
select (select COUNT(id) FROM instance where not name = 'erf' and not tiername = 'wer' and type='app') as app, (select COUNT(1) FROM instance_2 where not name = 'visq' and not name = 'werf' and type='adc') as adc from dual;`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…