Re: A join of 2 tables with sum(column) > 30

From: "Igor Neyman" <ineyman(at)perceptron(dot)com>
To: "Alexander Farber" <alexander(dot)farber(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: A join of 2 tables with sum(column) > 30
Date: 2011-03-16 14:05:25
Message-ID: F4C27E77F7A33E4CA98C19A9DC6722A20746F609@EXCHANGE.corp.perceptron.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Alexander Farber [mailto:alexander(dot)farber(at)gmail(dot)com]
> Sent: Tuesday, March 15, 2011 5:45 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: A join of 2 tables with sum(column) > 30
>
> And same for a simple select-query from1 table (w/o join):
>
> # select id from pref_match where sum(completed) > 30 group by id;
> ERROR: aggregates not allowed in WHERE clause LINE 1: select
> id from pref_match where sum(completed) > 30 group by...
> ^
>

You should "HAVING" close (not "WHERE") for an aggregate as a condition:

Select id, sum(col1) from tab
Where id > 10
Group by id
Having sum)col1) >30;

Spend some time reading basic SQL docs/books - it'll help you
tremendously.

Regards,
Igor Neyman

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Manos Karpathiotakis 2011-03-16 14:35:57 Re: Maximum number of tables
Previous Message Sergey Urlin 2011-03-16 13:27:21 user mapping options question