Search Postgresql Archives

Re: Refining query statement [DONE]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux