Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6meN-0001ML-Ji for pgsql-sql@arkaria.postgresql.org; Sun, 08 Sep 2019 02:09:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6meL-00081q-BI for pgsql-sql@arkaria.postgresql.org; Sun, 08 Sep 2019 02:09:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6meL-00081i-2k for pgsql-sql@lists.postgresql.org; Sun, 08 Sep 2019 02:09:57 +0000 Received: from mail02.mbizgroup.biz ([66.220.9.54] helo=mail.drivehq.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6meH-0000Lk-9b for pgsql-sql@lists.postgresql.org; Sun, 08 Sep 2019 02:09:56 +0000 Received: from (192.168.10.210) by EM244o80 with SMTP User ID0; Sun, 08 Sep 2019 02:09:48 GMT Received: from 60.111.238.211 (60.111.238.211) by mail.drivehq.com with HTTPUserID9736706; Sun, 08 Sep 2019 02:09:45 GMT X-Priority: 3 Message-ID: <2261310231000000009736706@www> From: "jj08" To: vyegorov@gmail.com, jj08@drivehq.com Cc: pgsql-sql@lists.postgresql.org Subject: RE:Re: RE:Re: A complex SQL query Date: Sat, 07 Sep 2019 19:09:45 -0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_226131023_9736706_637034801852222136" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_226131023_9736706_637034801852222136 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hello Vicor! It works!!! Thank you very much. = = = = --From: vyegorov@gmail.com --To: jj08@drivehq.com --CC: pgsql-sql@lists.postgresql.org --Date: 9/7/2019 2:33:40 PM --Subject: Re: RE:Re: A complex SQL query = =D1=81=D0=B1, 7 =D1=81=D0=B5=D0=BD=D1=82. 2019 =D0=B3. =D0=B2 21:23, jj0= 8 <jj08@drivehq.com>: = To Janis or other members of the forum: = My sample table contains other columns as well. = One of the columns that I did not include in my first message is "= position". The last table has been modified as follows: = +--------+----------+------------+------------------------+ | usr_id | employer | position + start_date | end_date | +--------+----------+------------+------------------------+ | A | Goo | CTO | | 201904 | = | A | Micro | Mgr | 201704 | 201903 | = | B | Micro | Engg_Mgr | 201706 | - | | B | Goo | Researcher | 201012 | 201705 | | B | Micro | Postdoc | 201001 | 201011 | +--------+-= ---------+------------+------------------------+ = SELECT DISTINCT ON (usr_id) * FROM employment WHERE employer=3D'Micro' ORDER BY usr_id, start_date DESC; = -- Victor Yegorov = = ------------------------- Online Storage & Sharing, Online Backup, FTP / Email Server Hosting and= More. = Drive Headquarters. Top quality services designed for business! Sign u= p free at: www.DriveHQ.com . = ------=_NextPart_226131023_9736706_637034801852222136 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Hello Vi= cor!

It works!!!

Thank you very much.





--From: vyegorov@gmail.com
--To: jj08@drivehq.com
--CC: pgsql-sql@lists.postgresql.org
--Date: 9/7/2019 2:33:40 PM
--Subject: Re: RE:Re: A complex SQL query

To Janis or other members of the forum:

My sample table contains other columns as well.

One of the columns that I did not include in my first message is "p= osition".
The last table has been modified as follows:

+--------+----------+------------+------------------------+
| usr_id | employer | position   + start_date | end_date = |
+--------+----------+------------+------------------------+
| A      | Goo      | = CTO        |    &= nbsp;       | 201904    |&n= bsp;       
| A      | Micro    | Mgr &= nbsp;      | 201704     | 2= 01903    |

| B      | Micro    | Engg_Mgr&n= bsp;  | 201706     | -    &= nbsp;    |
| B      | Goo      | = Researcher | 201012     | 201705    |=
| B      | Micro    | Postdoc&nb= sp;   | 201001     | 201011  &nb= sp; |
+--------+----------+------------+------------------------+

SELECT DISTINCT ON (usr_id)
       *
  FROM employment
 WHERE employer=3D'Micro'
 ORDER BY usr_id, start_date DESC;
 
--
Victor Yegorov

-------------------------
Online Storage & Sharing, Online Backup, FTP / Email Server Hosting and = More.
Drive Headquarters. Top quality services designed for business!
Sign up free at: www.DriveHQ.com. =
------=_NextPart_226131023_9736706_637034801852222136--