public inbox for [email protected]  
help / color / mirror / Atom feed
From: Shaozhong SHI <[email protected]>
To: Marcos Pegoraro <[email protected]>
Cc: pgsql-sql <[email protected]>
Subject: Re: Change detection
Date: Fri, 9 Dec 2022 13:14:15 +0000
Message-ID: <CA+i5JwZiEUgZZBqq04YQ1jBh=d7TBA_MFGC8R9yg66x_pwZQbg@mail.gmail.com> (raw)
In-Reply-To: <CAB-JLwZCEZNs_2jpd1UxRhC1=L3X0VeubokhQ5QBvhz3RckcZA@mail.gmail.com>
References: <CA+i5JwZ+XmOF6P4Lo=UTVUJBSQN4EyQL-fe7t4XTLPB9bwq9aQ@mail.gmail.com>
	<CAB-JLwZCEZNs_2jpd1UxRhC1=L3X0VeubokhQ5QBvhz3RckcZA@mail.gmail.com>

Thanks, Marcos.  It worked well.  Regards, David

On Fri, 9 Dec 2022 at 13:06, Marcos Pegoraro <[email protected]> wrote:

> Data
>>
>> Staff_ID    Name   Department            Year
>> 1                Tom    Sales                     1990
>> 2                 Tom      Sales                   1991
>> 3                 Tom      Sales                   1991
>> 4                 Tom      Management         1992
>> 4                 Tom     Management           1992
>>
>> select *, coalesce(lag(department) over(order by year), department) <>
> department Changed from (Values (1, 'Tom', 'Sales', 1990),(2, 'Tom',
> 'Sales', 1991),(3, 'Tom', 'Sales', 1991),(4, 'Tom', 'Management', 1992),(4,
> 'Tom', 'Management', 1992)) as x(Staff_ID, Name, Department, Year);
>  staff_id | name | department | year | changed
> ----------+------+------------+------+---------
>         1 | Tom  | Sales      | 1990 | f
>         2 | Tom  | Sales      | 1991 | f
>         3 | Tom  | Sales      | 1991 | f
>         4 | Tom  | Management | 1992 | t
>         4 | Tom  | Management | 1992 | f
> (5 rows)
>
>


view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Change detection
  In-Reply-To: <CA+i5JwZiEUgZZBqq04YQ1jBh=d7TBA_MFGC8R9yg66x_pwZQbg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox