On Wed, Mar 4, 2009 at 9:24 AM, Waylan Limberg wrote:
>
> On Mar 3, 8:55 am, Ross wrote:
> > I have started using aggregation, but it seems to ignore any slicing I
> > do on a QuerySet before calling aggregate. This is what I'm doing:
> >
> >
On Mar 3, 8:55 am, Ross wrote:
> I have started using aggregation, but it seems to ignore any slicing I
> do on a QuerySet before calling aggregate. This is what I'm doing:
>
> Product.objects.order_by("-price")[:100].values("price").aggregate(Max
> ("price"), Min("price"))
>
On Tue, Mar 3, 2009 at 11:46 AM, Ross wrote:
>
> As I thought about it more, I came up with something similar to what
> both of you suggested. Django's query language has made my SQL
> knowledge suffer a bit--your explanation about why the limit won't
> work makes sense, Jeff.
As I thought about it more, I came up with something similar to what
both of you suggested. Django's query language has made my SQL
knowledge suffer a bit--your explanation about why the limit won't
work makes sense, Jeff.
Thanks a lot for the suggestions.
On Mar 3, 10:39 am, Jeff FW
This time I didn't, apparently, read what you wanted exactly. Here I
was, talking about sums, when all you want are the minimum and
maximum. Apparently, I shouldn't answer mailing lists in the
morning.
Anyway, *most* of what I said holds true, as min and max work pretty
much the same way as
Responded too quickly :-)
If you're already getting a list of the top 100 products (and
displaying them, I assume, in a loop,) then totalling up the prices in
Python really won't hurt at all. I'd only suggest going with my
*previous* suggestion if you *weren't* already fetching the top 100
On Tue, Mar 3, 2009 at 11:32 AM, Ross wrote:
>
> Do you know a good way to do what I am trying to do? I can write a
> quick for loop to do the work, but I was hoping to offload some of the
> work to the database since it is much faster than a Python for loop.
>
> I have a set
The behavior is there because you can't limit an aggregate function in
(AFAIK) SQL in that way. It just doesn't make sense--what would this
actually mean?
select sum(price) from product limit 100;
Really, you'd be limiting the number of *rows* of sum returned, which,
unless you're using GROUP,
Do you know a good way to do what I am trying to do? I can write a
quick for loop to do the work, but I was hoping to offload some of the
work to the database since it is much faster than a Python for loop.
I have a set of say 10,000 Product models. I want to get a list of the
100 with the
On Tue, Mar 3, 2009 at 8:55 AM, Ross wrote:
>
> I have started using aggregation, but it seems to ignore any slicing I
> do on a QuerySet before calling aggregate. This is what I'm doing:
>
> Product.objects.order_by("-price")[:100].values("price").aggregate(Max
> ("price"),
I have started using aggregation, but it seems to ignore any slicing I
do on a QuerySet before calling aggregate. This is what I'm doing:
Product.objects.order_by("-price")[:100].values("price").aggregate(Max
("price"), Min("price"))
I want the maximum and minimum price for the products with
11 matches
Mail list logo