Re: Refining query statement

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Refining query statement
Date: 2019-01-15 15:54:57
Message-ID: bf7e79c6-0fa4-f730-dfdc-175576db8d66@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/15/19 7:39 AM, 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:
>
> select (C.contact_id, C.lname, C.fname, C.direct_phone, O.org_name,
> A.next_contact)
> from Contacts as C, Organizations as O, Activities as A
> where C.org_id = O.org_id and C.contact_id = A.contact_id and
>       A.next_contact <= 'today' and A.next_contact > '2018-12-31' and
>       A.next_contact is not null;
>
> but would benefit from tweaking. When I have had multiple contacts with
> someone I want only the most recent one displayed, not all, and they should
> be no more ancient than a defined period (e.g., a month).
>
>   I want to learn how to make this query cleaner and more flexible. When I
> write the UI for this I want to be able to specify a data range in addition
> to a fixed 'today'. Pointers on what to read will be very helpful.

For the above I could see using a datepicker widget that allows for
multidate select. The specifics would depend on the software you are
using to write the UI.

>
> TIA,
>
> Rich
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-01-15 15:56:01 Re: Using psql variables in DO-blocks
Previous Message Andreas Joseph Krogh 2019-01-15 15:51:09 Using psql variables in DO-blocks