Re: [SQL] aggregate query

2007-05-29 Thread Raj A
Thank you guys! I'm currently migrating an Oracle database to postgres and have created tables using the scripts that were readily available. Glad I can now improve this old system. On 29/05/07, Gregory Stark <[EMAIL PROTECTED]> wrote: "Andrew Kroeger" <[EMAIL PROTECTED]> writes: > Raj A wrote

Re: [SQL] aggregate query

2007-05-29 Thread Gregory Stark
"Andrew Kroeger" <[EMAIL PROTECTED]> writes: > Raj A wrote: >> I have a table >> >> CREATE TABLE survey_load >> ( >> meter_id character(5) NOT NULL, >> number_of_bays integer NOT NULL, >> bay_1_use integer, >> bay_2_use integer, >> bay_3_use integer, >> bay_4_use integer, >> bay_5_use inte

Re: [SQL] aggregate query

2007-05-29 Thread Andrew Kroeger
Raj A wrote: > I have a table > > CREATE TABLE survey_load > ( > meter_id character(5) NOT NULL, > number_of_bays integer NOT NULL, > bay_1_use integer, > bay_2_use integer, > bay_3_use integer, > bay_4_use integer, > bay_5_use integer, > date date NOT NULL, > inspection_id integer NOT NU

[SQL] aggregate query

2007-05-28 Thread Raj A
I have a table CREATE TABLE survey_load ( meter_id character(5) NOT NULL, number_of_bays integer NOT NULL, bay_1_use integer, bay_2_use integer, bay_3_use integer, bay_4_use integer, bay_5_use integer, date date NOT NULL, inspection_id integer NOT NULL DEFAULT, ) How do i present an agg

Re: [SQL] Aggregate query for multiple records

2004-08-28 Thread Josh Berkus
Scott, > Unfortunately, your revised query works like a charm except for the > fact that prd_data."date" - prd2."date" + 1 give incorrect values when > the year wraps, see in the output below. Need to conditionally > subtract 88 from the date or use an incrementing count() function > instead of d

Re: [SQL] Aggregate query for multiple records

2004-08-28 Thread Scott Gerhardt
Greg Stark <[EMAIL PROTECTED]> writes: [ nice example snipped ] ... Also, you'll have to change it to use reals. That part, at least, can be worked around as of 7.4: use polymorphic functions. You can declare the functions and aggregate as working on anyelement/anyarray, and then they will automa

Re: [SQL] Aggregate query for multiple records

2004-08-28 Thread Tom Lane
Greg Stark <[EMAIL PROTECTED]> writes: > [ nice example snipped ] > ... Also, you'll have to change it to use reals. That part, at least, can be worked around as of 7.4: use polymorphic functions. You can declare the functions and aggregate as working on anyelement/anyarray, and then they will au

Re: [SQL] Aggregate query for multiple records

2004-08-28 Thread Greg Stark
Scott Gerhardt <[EMAIL PROTECTED]> writes: > Hello, I am new to the list, my apology if this question is beyond the scope or > charter of this list. > > My questions is: > What is the best method to perform an aggregate query to calculate sum() values > for each distinct wid as in the example be

Re: [SQL] Aggregate query for multiple records

2004-08-27 Thread Josh Berkus
Scott, > >> I tried your query but it doesn't seem to work. The interpreter > >> expects prd2.date to be grouped but this doesn't make sence, see > >> below: > > > > Oh, yeah, darn it. > > > > Hmmm ... maybe you could explain the purpose of selecting just 6? > > This query > > is going to get a *

Re: [SQL] Aggregate query for multiple records

2004-08-27 Thread Josh Berkus
Scott, > > SELECT wid, > > (SELECT SUM(oil) FROM prd_data pd2 > > WHERE pd2.wid = prd_data.wid ORDER BY "date" LIMIT 6) as tot_oil, > > (SELECT SUM(hours) FROM prd_data pd2 > > WHERE pd2.wid = prd_data.wid ORDER BY "date" LIMIT 6) as tot_hours > > FROM prd_data > > ORDER BY wid;

Re: [SQL] Aggregate query for multiple records

2004-08-27 Thread Troy
shouldn't take that long, I would think. You have indexes on wid and date? Troy > > Hello, I am new to the list, my apology if this question is beyond the > scope or charter of this list. > > My questions is: > What is the best method to perform an aggregate query to calculate > sum() values

Re: [SQL] Aggregate query for multiple records

2004-08-26 Thread Josh Berkus
Scott, > Hello, I am new to the list, my apology if this question is beyond the > scope or charter of this list. We have a charter? Why didn't anyone tell me? > My questions is: > What is the best method to perform an aggregate query to calculate > sum() values for each distinct wid as in t

[SQL] Aggregate query for multiple records

2004-08-25 Thread Scott Gerhardt
Hello, I am new to the list, my apology if this question is beyond the scope or charter of this list. My questions is: What is the best method to perform an aggregate query to calculate sum() values for each distinct wid as in the example below, but except for all wid's (not just WHERE wid='01/