pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
help formualting a query 2+ messages / 2 participants [nested] [flat]
* help formualting a query @ 2019-09-08 23:11 stan <stanb@panix.com> 2019-09-08 23:23 ` Re: help formualting a query Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: stan @ 2019-09-08 23:11 UTC (permalink / raw) To: pgsql-general@lists.postgresql.org I am having a hard time figuring out to do this, the SQL way. Doing in a procedural way with a foreach would be deasy, but I suspect that a properly formulated SQL query can achieve this. I have a table that contains a series of rows. Each row has a project key, a start date, and an end date. There are multiple rows with different start and end dates for each project. I need to return something that contains, one row per project key, with the min(star date) and max(end date) for ALL the records for that given project. Any suggestions? -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: help formualting a query 2019-09-08 23:11 help formualting a query stan <stanb@panix.com> @ 2019-09-08 23:23 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2019-09-08 23:23 UTC (permalink / raw) To: stan <stanb@panix.com>; +Cc: pgsql-general@lists.postgresql.org stan <stanb@panix.com> writes: > I have a table that contains a series of rows. Each row has a project key, > a start date, and an end date. There are multiple rows with different start > and end dates for each project. > I need to return something that contains, one row per project key, with the > min(star date) and max(end date) for ALL the records for that given > project. Maybe I'm misunderstanding something, but isn't this just select project_key, min(start_date), max(end_date) from my_table group by project_key ?? regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-09-08 23:23 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-09-08 23:11 help formualting a query stan <stanb@panix.com> 2019-09-08 23:23 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox