简体   繁体   中英

Handling SCD type 2 table

I have this table:

id  c1  c2  c3

A   Y   Y   N
B   Y   N   Y
C   Y   Y   N
C   Y   Y   N
D   Y   Y   N
D   N   N   Y
E   Y   Y   N
E   Y   N   N
E   N   Y   N
F   Y   Y   N
F   Y   Y   N
G   Y   N   N
G   Y   N   Y

I want to check if c1 and c3 value for the same id has one 'Y' then 'Y' else 'N', if c2 value for the same id has ONE 'N' then 'N' ELSE 'Y', as follows:

id  c1 c2 c3
A   Y  Y  N
B   Y  N  Y
C   Y  Y  N
D   Y  N  Y
E   Y  N  N
.
.
.

i have no idea what to do !


I think you can use aggregation.

SELECT id,
       max(c1) c1,
       min(c2) c2,
       max(c3) c3
       FROM elbat
       GROUP BY id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM