Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

sqlalchemy + frasco , recebendo todos os posts por dia


Eu não faria isso em uma consulta, mas sim criaria o agrupamento desejado no lado do python:
# get desired posts (add your filters etc)
posts = session.query(Post).order_by(Post.time)

# create a dictionary, where key is the date(-only), and values are the posts of that day
from collections import defaultdict
grouped = defaultdict(list)
for post in posts:
    dat = post.time.date()
    grouped[dat].append(post)

# iterate over new grouped structure
for dat, posts in sorted(grouped.items()):
    print dat
    for post in posts:
        print '  ', post