<wince> Now I've figured why I don't get replies, I'm sending again.

Intro:
I have a table that contains much data like this:
 SELECT distinct on  (date) asx_code,date,open,high,low,close from
sales_summaries where asx_code =  'TLSCA' and date >= '2006-12-01' order
by date, time desc  limit 10;
SELECT distinct on  (date) asx_code,date,open,high,low,close,volume from
sales_summaries where asx_code =  'TLSCA' and date >= '2006-12-01' order
by date, time desc  limit 10;
 asx_code |    date    | open  | high  |  low  | close |  volume
----------+------------+-------+-------+-------+-------+----------
 TLSCA    | 2006-12-01 | 2.330 | 2.340 | 2.300 | 2.300 | 29165222
 TLSCA    | 2006-12-04 | 2.310 | 2.320 | 2.280 | 2.300 | 14973667
 TLSCA    | 2006-12-05 | 2.310 | 2.320 | 2.300 | 2.320 | 23238175
 TLSCA    | 2006-12-06 | 2.320 | 2.400 | 2.320 | 2.380 | 58357650
 TLSCA    | 2006-12-07 | 2.380 | 2.450 | 2.380 | 2.450 | 64005594
 TLSCA    | 2006-12-08 | 2.450 | 2.520 | 2.450 | 2.510 | 82831560
 TLSCA    | 2006-12-11 | 2.500 | 2.550 | 2.500 | 2.540 | 38711749
 TLSCA    | 2006-12-12 | 2.560 | 2.620 | 2.560 | 2.610 | 61709325
 TLSCA    | 2006-12-13 | 2.600 | 2.600 | 2.540 | 2.590 | 39455386
 TLSCA    | 2006-12-14 | 2.600 | 2.650 | 2.600 | 2.620 | 30675340
(10 rows)


Some may guess (correctly) that this is price information from a stock
exchange. What I want to do is consolidate the data into weekly (for
starters) periods. Writing a Java (or other procedural language) program
to read row by row is fairly straightforward. What I want to do is to do
it entirely in SQL.

I've perused my book (Mastering SQL by Martin Gruber), the postgresql
docs (I have versions here on RHEL (Centos) 4, FC5,6, Debian Testing -
up to 8,1) and I don't see how to choose the entry for the first open
column, the last close. Max, min and average will do nicely for the
others, and converting the date to an interval then dividing by seven
seems to work nicely for creating my groups,

The results I expect from the above data are
TLSCA 2006-12-07 2.330 2.450 2.280 2.450 mumble
TLSCA 2006-12-14 2.450 2.650 2.450 2.620 mumble

The question is, "How can I do this in SQL?"

May the pedants ignore that these weeks don't run Monday to Friday:-)

fwiw I'm working on Linux; thus far everything's done in bash scripts
aided by friends such as lynx, grep awk and (Of course) psql.


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to