pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joel Burton <joel@joelburton.com>
To: Timothy J Hitchens <tim@hitcho.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: GROUPING
Date: Sun, 14 Oct 2001 11:34:20 -0400 (EDT)
Message-ID: <Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com> (raw)
In-Reply-To: <001101c15384$7d0cbda0$0a00a8c0@father>

On Sat, 13 Oct 2001, Timothy J Hitchens wrote:

> It's been a while since I used postgresql but today I have converted one
> of my web apps but with one small problem.  I goto do a group as
> designed and executed in mysql and I get told that this and this must be
> part of the aggreate etc I am puzzled and wonder if someone could bring
> me up to stratch with grouping in postgresql this is my current sql:
>
> SELECT * FROM telemetry WHERE beat > 12 GROUP BY buid;
>
> Result:
>
> Attribute telemetry.rpvuid must be GROUPed or used in an aggregate
> function
>
>
> Oh then if I include rpvuid I get you must include this field and on it
> goes.

Normally, GROUP BY is used to group up records to look at an aggregate.
For example, if you have this table of your friends:

CREATE TABLE friends (
  friend TEXT,
  country_code CHAR(2),
  income FLOAT,
);

I could get a count of how many friends lived in each country by:

SELECT country_code, COUNT(*) FROM friends GROUP BY country_code;

Or I could get the average amount of money made by friends in each country
with:

SELECT country_code, avg(income) FROM friends GROUP BY country_code;


In other words, when you GROUP BY, you're looking for an aggregate
(a function that is applied to a group and returns a single value,
such as average, minimum, maximum, count, etc.)

Can you be more specific about what you're actually trying to accomplish?





view thread (5+ messages)  latest in thread

Message-ID: <Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com>
Permalink:  ../Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com

 · 

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: joel@joelburton.com, tim@hitcho.com.au
  Subject: Re: GROUPING
  In-Reply-To: <Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com>
  References: <001101c15384$7d0cbda0$0a00a8c0@father> <Pine.LNX.4.30.0110141131001.6917-100000@temp.joelburton.com>

* 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