Search Postgresql Archives

trick problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux