At 10:39 AM -0600 11/6/01, Rick Emery wrote:
>Is this what you want (assuming you want top 10 items)?
>
>select avg(TABLE.Field_In_Question) from TABLE order by
>Primary_key,TABLE.timestamp DESC) LIMIT 10 DESC
That won't work. LIMIT is applied after everything else.
Select the 10 rows you want into a temporary table, then run
the summary table on that.
>
>-----Original Message-----
>From: Robert Williams [mailto:rw@stripped]
>Sent: Tuesday, November 06, 2001 10:07 AM
>To: mysql@stripped
>Subject: mySQL query question
>
>
>
>If I wanted to get the average of a certain field in the top n records of
>a mySQL table how would I do that? In MS-SQL I would do:
>
>select avg(TABLE.Field_In_Question) from TABLE
>where TABLE.Primary_Key IN (select top n TABLE.Primary_Key from TABLE
>order by TABLE.timestamp DESC)
>
>But I know mySQL doesn't support those sorts of sub-selects. Any ideas?
>
>rw
>
>
>
>
>---------------------------------------------------------------------
>Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
>To request this thread, e-mail <mysql-thread90222@stripped>
>To unsubscribe, e-mail <mysql-unsubscribe-remery=excel.com@stripped>
>Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>
>---------------------------------------------------------------------
>Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
>To request this thread, e-mail <mysql-thread90226@stripped>
>To unsubscribe, e-mail <mysql-unsubscribe-paul=snake.net@stripped>
>Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php