| From: | Rich Shepard <rshepard(at)appl-ecosys(dot)com> |
|---|---|
| To: | pgsql-general(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Refining query statement [DONE] |
| Date: | 2019-01-18 15:56:22 |
| Message-ID: | alpine.LNX.2.20.1901180750230.4540@salmo.appl-ecosys.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | George Woodring | 2019-01-18 18:23:51 | Why adding BEFORE TRIGGER affect client CPU? |
| Previous Message | Adrian Klaver | 2019-01-18 15:38:36 | Re: Upgrading from 9.2.15 to 9.4.20 |