Running Average

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Elliot English

    #1

    Running Average

    How can I get mysql to do a running average of a given field using dates
    from another column so that the average for each element is for a given time
    period rather than from the 5 rows next to the element?

    --
    Elliot English,
    eenglish_ca@yah oo.ca



  • Jon Kraft

    #2
    Re: Running Average

    Elliot English wrote:
    [color=blue]
    > How can I get mysql to do a running average of a given field using dates
    > from another column so that the average for each element is for a given
    > time period rather than from the 5 rows next to the element?[/color]

    Hi Elliot,

    Something like:

    SELECT AVG(somefield) FROM sometable WHERE datefield BETWEEN '2003-08-10'
    AND '2003-08-26';

    HTH;
    JOn

    Comment

    • Jon Kraft

      #3
      Re: Running Average

      Elliot English wrote:
      [color=blue]
      > How can I get mysql to do a running average of a given field using dates
      > from another column so that the average for each element is for a given
      > time period rather than from the 5 rows next to the element?[/color]

      Hi Elliot,

      Something like:

      SELECT AVG(somefield) FROM sometable WHERE datefield BETWEEN '2003-08-10'
      AND '2003-08-26';

      HTH;
      JOn

      Comment

      • Jon Kraft

        #4
        Re: Running Average

        Elliot English wrote:
        [color=blue]
        > How can I get mysql to do a running average of a given field using dates
        > from another column so that the average for each element is for a given
        > time period rather than from the 5 rows next to the element?[/color]

        Hi Elliot,

        Something like:

        SELECT AVG(somefield) FROM sometable WHERE datefield BETWEEN '2003-08-10'
        AND '2003-08-26';

        HTH;
        JOn

        Comment

        Working...