Re: Refining query statement [DONE] - Mailing list pgsql-general

From Rich Shepard
Subject Re: Refining query statement [DONE]
Date
Msg-id alpine.LNX.2.20.1901180750230.4540@salmo.appl-ecosys.com
Whole thread Raw
In response to Refining query statement  (Rich Shepard <rshepard@appl-ecosys.com>)
List pgsql-general
On Tue, 15 Jan 2019, Rich Shepard wrote:

> Working with my sales/client management system using psql I have a select
> statement to identify contacts to be made. This statement works:

With much patient advice from Adrian, David, Thomas, and Ron I fixed the
schema and the query statement. To close this thread I post the query that
meets my goal and provide the information I need. Formatting this as a
report will be the job of SQLAlchemy and wxPython.

/* This query selects all contact information and notes from those people
    whose next_contact date is today or earlier; only active persons. */

/* Specify columns */
SELECT p.lname, p.fname, p.direct_phone, p.active, o.org_name,
        a.act_date, a.act_type, a.notes, a.next_contact, a.comment
/* Specify tables. */ 
FROM People AS p
      JOIN Organizations AS o ON o.org_id = p.org_id
      JOIN Activities AS a ON a.person_id = p.person_id
/* Specify rows */ 
WHERE p.active = TRUE AND
       a.next_contact <= 'today'::date
GROUP BY o.org_name, p.person_id, a.person_id, a.act_date, a.act_type,
       a.next_contact
ORDER BY p.person_id, a.next_contact DESC;

I really appreciate your help.

Best regards,

Rich


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Upgrading from 9.2.15 to 9.4.20
Next
From: George Woodring
Date:
Subject: Why adding BEFORE TRIGGER affect client CPU?