<div dir="ltr"><div>Of course, as soon as I send the email, I find something that works:<br><br>models.select((r.date, models.count(r)) for r in models.Result if r.date >= datetime.date.today() - datetime.timedelta(days=10))[:]<br><br></div>Is this the most efficient method?<br><div><div class="gmail_extra"><br><div class="gmail_quote">On 5 November 2014 08:02, Matthew Bell <span dir="ltr"><<a href="mailto:matthewrobertbell@gmail.com" target="_blank">matthewrobertbell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi, <br><br>I have naively tried to execute this query:<br><br>models.select((r.date, models.count(r.date)) for r in models.Result if r.date >= datetime.date.today() - datetime.timedelta(days=10)).without_distinct()<br><br></div>With the aim of counting how many times each date appears. I was doing this with collections.Counter, but this doesn't scale to millions of results (far too much CPU and memory used). What query can I use to make the database do the work?<br><br>Thanks<span class=""><font color="#888888"><br><div><div>-- <br><div>Regards,<br><br>Matthew Bell<br></div>
</div></div></font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Regards,<br><br>Matthew Bell<br></div>
</div></div></div>