GROUP BY difficulties - Mailing list pgsql-novice

From Michael Rowan
Subject GROUP BY difficulties
Date
Msg-id 3D4C1DD3-2B33-423A-B290-EF1AF1553DA0@internode.on.net
Whole thread Raw
List pgsql-novice
The following query successfully selects a row for every property
advertised by selling agents after a date (thanks due to this list
already).

SELECT * FROM (SELECT DISTINCT ON (property_id)
Agent.first_name, Agent.last_name,  Agent.id
FROM Advertisement, Agent, Property
WHERE Property.id = Advertisement.property_id
AND Agent.id = Advertisement.agent_id
AND Advertisement.date >= '2009-01-01'
ORDER BY property_id, date DESC) ss ORDER BY Agent.last_name,
Agent.first_name;

I need to add to the query such that rather than returning a number of
identical rows for each Agent, it returns only one row per Agent and
includes each agents row-count.

Any help gratefully received.  GROUP BY seems pretty tricky to use.

Michael Rowan
mike.rowan@internode.on.net

11 Kingscote Street
ALBERTON
South Australia 5014

tel 618 8240 3993




pgsql-novice by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: How to get the all tables, triggers, fuctions available in my database
Next
From: Wojtek
Date:
Subject: Re: How to get the all tables, triggers, fuctions available in my database