List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:November 7 2001 2:56am
Subject:RE: mySQL query question
View as plain text  
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

Thread
how optimize and put in order the row?rino.mail6 Nov
  • Re: how optimize and put in order the row?Dibo Chen6 Nov
    • mySQL query questionRobert Williams6 Nov
  • Re: how optimize and put in order the row?Carl Troein6 Nov
    • Re: how optimize and put in order the row?rino.mail8 Nov
      • Re: how optimize and put in order the row?Kodrik8 Nov
  • Re: how optimize and put in order the row?Bill Adams8 Nov
  • Re: how optimize and put in order the row?Fournier Jocelyn [Presence-PC]8 Nov
  • Re: how optimize and put in order the row?Bill Adams8 Nov
  • Re: how optimize and put in order the row?Jeff Isom8 Nov
  • Re: how optimize and put in order the row?DL Neil9 Nov
RE: mySQL query questionRick Emery6 Nov
  • RE: mySQL query questionRobert Williams6 Nov
RE: mySQL query questionRick Emery6 Nov
RE: mySQL query questionPaul DuBois7 Nov