title: Weighted moving average in Amazon Redshift
body: <p>Is there a way to calculate a weighted moving average with a fixed window size in Amazon Redshift? In more detail, given a table with a date column and a value column, for each date compute the weighted average value over a window of a specified size, with weights specified in an auxiliary table.</p>
  
  <p>My search attempts so far yielded plenty of examples for doing this with window functions for <em>simple average</em> (without weights), for example <a href="http://tiku.io/questions/2328781/moving-average-filter-in-postgresql" rel="nofollow noreferrer">here</a>. There are also some related suggestions for postgres, e.g., <a href="https://stackoverflow.com/questions/8871426/how-to-calculate-an-exponential-moving-average-on-postgres">this SO question</a>, however Redshift's feature set is quite sparse compared with postgres and it doesn't support many of the advanced features that are suggested. </p>