Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Matthew Smith
Michael, Thanks heaps for that! Cheers, Matt Smith On Thu, 22 Dec 2005 01:37 pm, Michael Fuhr wrote: > On Thu, Dec 22, 2005 at 11:59:24AM +1100, Matthew Smith wrote: > > Sadly I am using 7.3, it seems that generate_series() is 8.0 and later. > > Yes, but it's easily written in PL/pgSQL for earl

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Michael Fuhr
On Thu, Dec 22, 2005 at 11:59:24AM +1100, Matthew Smith wrote: > Sadly I am using 7.3, it seems that generate_series() is 8.0 and later. Yes, but it's easily written in PL/pgSQL for earlier versions. Example: CREATE FUNCTION generate_series(integer, integer) RETURNS SETOF integer AS ' DECLARE

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Matthew Smith
Richard (and list), Thanks for the help! More below: On Wed, 21 Dec 2005 09:04 pm, Richard Huxton wrote: > Matthew Smith wrote: > > I want to form a query that returns the average total usage for each day > > of the week, eg: > > [snip] > > > To get this info, I am using the following query: > >

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Richard Huxton
Matthew Smith wrote: I want to form a query that returns the average total usage for each day of the week, eg: [snip] To get this info, I am using the following query: select dow as day, sum(sum_data)/count(dow) as avg_usage from (select extract('dow' from date_trunc('day', time)) as dow, sum

[SQL] Help on a complex query (avg data for day of the week)

2005-12-20 Thread Matthew Smith
Hello, I have a table containing a timestamp and data usage fields (among others). This table stores amounts of data usage and the times then the data was used, eg: time | data +-- 2005-03-26 09:32:43+11 | 162 I want to form a query that retu