Re: Setting Variable - (Correct)

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Ranieri Mazili <ranieri(dot)oliveira(at)terra(dot)com(dot)br>, pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: Setting Variable - (Correct)
Date: 2007-06-18 16:15:12
Message-ID: 7DA5333D-3437-4033-A222-128E541A04C2@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


On Jun 18, 2007, at 10:17 , Michael Glaesemann wrote:

> Looking over your function, I'm a little confused about what you're
> trying to do. I'm guessing the (final) result you're trying to get
> is the number of hours lost for each product per area per month for
> the three years prior to the provided date.

Or, rather, the number of hours lost per production area per month
for the three years prior to the provided date.

> SELECT date_trunc('month', production.production_date)::date
> AS production_period
> , product.id_production_area
> , sum(production_hours) as total_production_hours
> FROM production
> JOIN product USING (id_product)
> WHERE lost_hours = 'S'
> AND date_trunc('month', a.production_date)::date BETWEEN
> date_trunc('month', ? - 3 * interval '1 year')::date
> AND date_trunc('month', ?)::date;

Looks like I forgot the GROUP BY clause:

GROUP BY production_period, id_production_area

Michael Glaesemann
grzm seespotcode net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2007-06-18 16:25:58 Re: Postgres VS Oracle
Previous Message Jonah H. Harris 2007-06-18 16:10:30 Re: Postgres VS Oracle

Browse pgsql-sql by date

  From Date Subject
Next Message Chapilliquen Gutierrez Eduardo 2007-06-18 16:30:50 Ejecutar \copy desde VB
Previous Message Michael Glaesemann 2007-06-18 15:17:45 Re: Setting Variable - (Correct)