Re: [OFFTOPIC] Query Help - Mailing list pgsql-general

From Jean-Luc Lachance
Subject Re: [OFFTOPIC] Query Help
Date
Msg-id 3DED3E60.E632DA8@nsd.ca
Whole thread Raw
In response to [OFFTOPIC] Query Help  (Hunter Hillegas <lists@lastonepicked.com>)
List pgsql-general
Try:

select username, avg(date_difference) from sample_request_average_days
group by salesperson, to_char( date_shipped, 'YYYYMM');


Hunter Hillegas wrote:
>
> Someone asked me to create a query for them that would compute some averages
> for them over time.
>
> Basically I have a view that looks like this:
>
>  sample_request_line_item_number | integer                  |
>  sample_origin                   | character varying        |
>  date_of_request                 | timestamp with time zone |
>  username                        | character varying        |
>  date_shipped                    | date                     |
>  date_difference                 | double precision         |
>
> I have a query that does what I need:
>
>
> date_shipped between '2002-11-01' and '2002-11-30' group by username;
>
> Basically it is getting the average number of days it took to ship something
> by salesperson, by month.
>
> The problem is that I want it to print the results for each month for which
> there are entries (without hard-coding dates).
>
> Is there any easy way to do this that I'm missing?
>
> Any help appreciated. Please reply off-list to minimize noise.
>
> Thanks,
> Hunter
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

pgsql-general by date:

Previous
From: Tycho Fruru
Date:
Subject: Re: Postgresql -- initial impressions and comments
Next
From: Bruce Momjian
Date:
Subject: Re: Postgresql -- initial impressions and comments