Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. # simplified schema
  2. my_table = Table('data', metadata,
  3. Column('id', Integer),
  4. Column('session', Integer),
  5. Column('tape', Integer),
  6. Column('status', Enum(['lost', 'in process', 'done'], name='status')),
  7.  
  8. PrimaryKeyConstraint(['id', 'session', 'tape'])
  9. )
  10.  
  11. statuses = select(
  12. [
  13. my_table.c.id,
  14. my_table.c.session,
  15. func.COUNT(my_table.c.id).label('tape_count'),
  16. func.COUNT(func.IF(my_table.c.status=='done', 1, 0)).label('done_count'),
  17. func.COUNT(func.IF(my_table.c.status=='lost', 1, 0)).label('lost_count')
  18. ],
  19. order_by=[my_table.c.id, my_table.c.session],
  20. group_by=[my_table.c.id, my_table.c.session]
  21. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement