trick problem - Mailing list pgsql-general

From 纪晓曦
Subject trick problem
Date
Msg-id 37a11ce00909031802g52397a3atbc55d7d6b8e2cf13@mail.gmail.com
Whole thread Raw
List pgsql-general
Consider the following relational schema about daily stock prices.
StockPrice (stockid; timeid; price)
We make the simplifying assumption that timeid is an integer that count the number
of days from a particular date in the past (that is, the stock prices on the x-th day can
be found by a simple selection condition of WHERE timeid = x).
Write the following queries in SQL.
Print out the 15-day moving averages of each stock sorted by stockid and timeid
(ascending order).
If the stock prices for a particular stock are
timeid price
5 10
6 12
7 14
then its 2-day moving averages will be
timeid 2-day moving average
6 11.0000000000000000
7 13.0000000000000000
Note that we want strict 15-day moving average, meaning that
1. There should be no 15-day moving average for the first 14 days (as shown in
the above example).
2.If there are missing data (e.g., the price for a stock at some date is missing)
within the 15-day (sliding) window, the computation on this window should
be abandoned.

I don't know how to do it without plsql

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: pg_ctl with unix domain socket?
Next
From: Scott Marlowe
Date:
Subject: Re: How do I store tables on a remote host?