trick problem

From: 纪晓曦 <sheepjxx(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: trick problem
Date: 2009-09-04 01:02:20
Message-ID: 37a11ce00909031802g52397a3atbc55d7d6b8e2cf13@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-09-04 02:24:44 Re: How do I store tables on a remote host?
Previous Message Adrian Klaver 2009-09-04 00:16:56 Re: pg_ctl with unix domain socket?