pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pete@phillipsfamily.freeserve.co.uk
To: pgsql-sql@postgresql.org
Subject: problem with subqueries
Date: Sat, 05 Oct 2002 22:19:31 +0000
Message-ID: <200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk> (raw)

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.



view thread (5+ messages)  latest in thread

Message-ID: <200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk>
Permalink:  ../200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk/
Also on:    postgresql.org/message-id/200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pete@phillipsfamily.freeserve.co.uk
  Subject: Re: problem with subqueries
  In-Reply-To: <200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk>
  References: <200210052219.g95MJVx01588@phillipsfamily.freeserve.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox