problem with subqueries

From: pete(at)phillipsfamily(dot)freeserve(dot)co(dot)uk
To: pgsql-sql(at)postgresql(dot)org
Subject: problem with subqueries
Date: 2002-10-05 22:19:31
Message-ID: 200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi

Any help appreciated - I have spent 2 days trying to get this query to
work!

I have an orders database and a customer database.

The orders database has a date field for each order.

Because I want to obtain a monthly breakdown, I created a view called
monthcustomer as this select:

select orders.ord_date, customer.cname,
date_part('month',orders.ord_date) AS "month",
date_part('year',orders.ord_date) AS "year",
orders.number_of_items;

Each month will have multiple numbers of items, so to get a monthly
breakdown I tried this:

select distinct year,month,
(select sum(monthcustomer.number_of_items) from monthcustomer where
monthcustomer.year=m.year and monthcustomer.month=m.month) as NumPots
from monthcustomer m;

This goes off and never comes back - CPU is hitting the top of the
chart! I have to ^C to interrupt it, as it runs for ages (I've left
this run for 10-20 minutes and it is still running).

I have indexes on the columns involved from the original tables.

Any help appreciated.

Pete

PS: Using pgsql 7.2-70 from Suse distribution.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-10-06 01:01:33 Re: problem with subqueries
Previous Message dev 2002-10-05 14:13:12 Re: enforcing with unique indexes..