Re: Re: avg() AND limit

2006-12-18 Thread Dan Buettner
I'm sure there is ... here's one way I can think of, a two-step process but doable in 3.23 I think. Use a server-side variable and a combination of the LIMIT and OFFSET features. SELECT id FROM items ORDER BY DATE DESC LIMIT 1 OFFSET 10 INTO @myid then SELECT AVG(cost) FROM items WHERE id >= @

Re: avg() AND limit

2006-12-18 Thread Dan Buettner
Yes, the LIMIT function affects number of rows returned, not number of rows evaluated. If you're on 4.1 or later, you could use a subselect. Assuming you have an ID field in your table, something like this: SELECT AVG(cost) FROM items WHERE id IN (SELECT id FROM items ORDER BY date DESC LIMIT 1