简体   繁体   中英

Comparing values between records in a table using Informatica PowerCenter

Consider a table with the following records in a Database:

>>> Table A:
Col_1  Col_2  Col_3
GGG     123    -
GGG     123    X
GGG     123    Y
KKK     786    X
MMM     999    Y
DDD     456    X
DDD     456    U

Wherever we have records with matching values in col_1 and col_2, and we have values X and Y in col_3, the records with X and Y must be deleted. In other cases, we should keep the records. For example in the above table, the output should look like this:

>>> Output_Table:
    Col_1  Col_2  Col_3
    GGG     123    -
    KKK     786    X
    MMM     999    Y
    DDD     456    X
    DDD     456    U

How this scenario can be implemented (using expression transformation, variable ports, lookup and so on...)? Any help would be greatly appreciated.

There can be multiple scenarios. And i am not sure if your issue is exactly like you described but i will answer as per your question.

Assuming Col_3 can have 'X','Y' - as hardcoded value you want to remove. The values you are trying to remvoe are hardcoded.

  1. First sort the data based on Col_1,Col_2.
  2. Then use EXP transformation and create 7 ports like below. Here we will compare one row with its previous row and see if they are same or not. If same, then concat col3 into one single column.
col1
col2
in_col3
v_col3= iif(v_prev_col1=col1 and v_prev_col2=col2,col3,v_col3||''||col3)
v_prev_col1=col1
v_prev_col2=col2
o_col3=v_col3
  1. After that use an aggregator - group by ports will be col1,col2. And then col3 will be MAX(o_col3) from expression before. Agg will stamp concatenated col3 into one single column.

  2. Then add a filter like below to check if you have XY or YX for duplicate rows.

iif(max_col3='XY' or reverse(max_col3)='XY',FALSE,TRUE)  -- You can place any hardcode values here.

EDIT: 5. Now, if you want to get original data (like in comments) excluding XY combination, then use a joiner. use a joiner now, join output from step 4 and output of step 1. It will be a normal join on Col_1,Col_2. And the output of the joiner will have no XY combination.

Whole mapping should look like this

           |->2.EXP-->3.AGG-->4.FIL--|  
-->1.SRT ->|------------------------>|->5.JNR--...--> TGT

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