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

>
> 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: <CAB-JLwZCEZNs_2jpd1UxRhC1=L3X0VeubokhQ5QBvhz3RckcZA@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