[SQL] update with multiple fields as aggregates

2008-05-03 Thread Alexy Khrabrov
I need to fill two columns of a Rats table from an Offset1 table, where for each Id row in Rats we need to fill an average offset and the sum of all offset from Offset1 with the same Id. I can create a derivative table like this: create table ofrats as (select customer_id as cid,avg(o),sum

[SQL] numbering rows on import from file

2008-05-02 Thread Alexy Khrabrov
Greetings -- I have a huge table of the form (integer,integer,smallint,date). Its origin is an ASCII file which I load with \copy. Now I want to number the rows, adding an id column as an autoincrement from a sequence. How should I do the import now for the sequence to work -- should I a

Re: [SQL] columns for count histograms of values

2008-05-01 Thread Alexy Khrabrov
Chester -- awesome! Exactly what the doctor ordered. Just one syntactic fix needed on 8.3.1: case when rating=1 then 1 else 0 end -- etc. Cheers, Alexy On Apr 30, 2008, at 4:12 PM, chester c young wrote: --- Alexy Khrabrov <[EMAIL PROTECTED]> wrote: Greetings -- I have a table

[SQL] columns for count histograms of values

2008-04-30 Thread Alexy Khrabrov
Greetings -- I have a table of the kind Ratings: id integer rating smallint -- where value can take any value in the range 1 to 5. Now I want to have a statistical table Stats of the form id integer min smallint max smallint avg real r1 integer r2 integer r3 integer r4 integer r5 integer -