Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # simplified schema
- my_table = Table('data', metadata,
- Column('id', Integer),
- Column('session', Integer),
- Column('tape', Integer),
- Column('status', Enum(['lost', 'in process', 'done'], name='status')),
- PrimaryKeyConstraint(['id', 'session', 'tape'])
- )
- statuses = select(
- [
- my_table.c.id,
- my_table.c.session,
- func.COUNT(my_table.c.id).label('tape_count'),
- func.COUNT(func.IF(my_table.c.status=='done', 1, 0)).label('done_count'),
- func.COUNT(func.IF(my_table.c.status=='lost', 1, 0)).label('lost_count')
- ],
- order_by=[my_table.c.id, my_table.c.session],
- group_by=[my_table.c.id, my_table.c.session]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement