Re: problem with subqueries

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: problem with subqueries
Дата
Msg-id 20021005175906.R58075-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на problem with subqueries  (pete@phillipsfamily.freeserve.co.uk)
Список pgsql-sql
On Sat, 5 Oct 2002 pete@phillipsfamily.freeserve.co.uk wrote:

> 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

That's going to run that inner select once for every row in monthcustomer
probably.

Would
select year, month, sum(monthcustomer.number_of_items) as NumPots frmo
monthcustomer m group by year, month;
have the same effect, get the sum of the items for each year/month
combination along with which year and month?




В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: problem with subqueries
Следующее
От: pete@phillipsfamily.freeserve.co.uk
Дата:
Сообщение: Re: problem with subqueries