pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
WHERE of an AGGREGATE ...
4+ messages / 3 participants
[nested] [flat]

* WHERE of an AGGREGATE ...
@ 2003-06-14 23:31 The Hermit Hacker <scrappy@postgresql.org>
  2003-06-14 23:58 ` Re: WHERE of an AGGREGATE ... deststar <deststar@blueyonder.co.uk>
  0 siblings, 1 reply; 4+ messages in thread

From: The Hermit Hacker @ 2003-06-14 23:31 UTC (permalink / raw)
  To: pgsql-sql


I have a query that looks like:

  SELECT SUM(bytes) AS traffic
    FROM traffic_table
GROUP BY ip;

I want to narrow that SELECT down to a subset, like:

   SELECT SUM(bytes) AS traffic
     FROM traffic_table
    WHERE traffic < ( 100 * 1024 * 1024 )
 GROUP BY ip;

which, of course, won't work, cause I need to do the GROUP BY before I do
the WHERE ... but there has to be a way of coding that so that it does
work :(

I'm overlooking something obvious here ... I think?

Thanks ...

Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: WHERE of an AGGREGATE ...
  2003-06-14 23:31 WHERE of an AGGREGATE ... The Hermit Hacker <scrappy@postgresql.org>
@ 2003-06-14 23:58 ` deststar <deststar@blueyonder.co.uk>
  2003-06-15 00:39   ` Re: WHERE of an AGGREGATE ... The Hermit Hacker <scrappy@postgresql.org>
  0 siblings, 1 reply; 4+ messages in thread

From: deststar @ 2003-06-14 23:58 UTC (permalink / raw)
  To: The Hermit Hacker <scrappy@postgresql.org>; +Cc: pgsql-sql

Isn't that what the having clause is about?
- Stuart

On Sun, 2003-06-15 at 00:31, The Hermit Hacker wrote:
> I have a query that looks like:
> 
>   SELECT SUM(bytes) AS traffic
>     FROM traffic_table
> GROUP BY ip;
> 
> I want to narrow that SELECT down to a subset, like:
> 
>    SELECT SUM(bytes) AS traffic
>      FROM traffic_table
>     WHERE traffic < ( 100 * 1024 * 1024 )
>  GROUP BY ip;
> 
> which, of course, won't work, cause I need to do the GROUP BY before I do
> the WHERE ... but there has to be a way of coding that so that it does
> work :(
> 
> I'm overlooking something obvious here ... I think?
> 
> Thanks ...
> 
> Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
> Systems Administrator @ hub.org
> primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: WHERE of an AGGREGATE ...
  2003-06-14 23:31 WHERE of an AGGREGATE ... The Hermit Hacker <scrappy@postgresql.org>
  2003-06-14 23:58 ` Re: WHERE of an AGGREGATE ... deststar <deststar@blueyonder.co.uk>
@ 2003-06-15 00:39   ` The Hermit Hacker <scrappy@postgresql.org>
  0 siblings, 0 replies; 4+ messages in thread

From: The Hermit Hacker @ 2003-06-15 00:39 UTC (permalink / raw)
  To: deststar <deststar@blueyonder.co.uk>; +Cc: pgsql-sql


perfect, its one of those that I've used so rarely, I never thought about
it ... thanks :)


On Sat, 15 Jun 2003, deststar wrote:

> Isn't that what the having clause is about?
> - Stuart
>
> On Sun, 2003-06-15 at 00:31, The Hermit Hacker wrote:
> > I have a query that looks like:
> >
> >   SELECT SUM(bytes) AS traffic
> >     FROM traffic_table
> > GROUP BY ip;
> >
> > I want to narrow that SELECT down to a subset, like:
> >
> >    SELECT SUM(bytes) AS traffic
> >      FROM traffic_table
> >     WHERE traffic < ( 100 * 1024 * 1024 )
> >  GROUP BY ip;
> >
> > which, of course, won't work, cause I need to do the GROUP BY before I do
> > the WHERE ... but there has to be a way of coding that so that it does
> > work :(
> >
> > I'm overlooking something obvious here ... I think?
> >
> > Thanks ...
> >
> > Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
> > Systems Administrator @ hub.org
> > primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 9: the planner will ignore your desire to choose an index scan if your
> >       joining column's datatypes do not match
>
>

Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Where of an aggregate
@ 2003-06-15 08:01 vali@voxline.ro
  0 siblings, 0 replies; 4+ messages in thread

From: vali@voxline.ro @ 2003-06-15 08:01 UTC (permalink / raw)
  To: pgsql-sql

HI!
Try this

select c.traffic from
(select sum(bytes) as traffic
    from traffic_table
group by ip) c where c.traffic<(100*1024*1024);




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-06-15 08:01 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-14 23:31 WHERE of an AGGREGATE ... The Hermit Hacker <scrappy@postgresql.org>
2003-06-14 23:58 ` deststar <deststar@blueyonder.co.uk>
2003-06-15 00:39   ` The Hermit Hacker <scrappy@postgresql.org>
2003-06-15 08:01 Where of an aggregate vali@voxline.ro

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