Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
Can anyone please help me with below problem.
I have a table like below
Qtr ID Weight Flag1 Flag2
Q1 123 10 - Y
Q1 123 20 - N
Q1 234 20 Y -
Q1 345 50 - -
I want to show the table like below when Flag1 is Y
Qtr ID Weight Flag1 Flag2
Q1 123 10 - Y
Q1 234 20 Y -
Q1 345 50 - -
Qtr ID Weight Flag1 Flag2
Q2 123 10 - Y
Q2 123 20 - N
Q2 234 50 N -
Q2 345 50 - -
I want to show the table like below when Flag1 is N
Qtr ID Weight Flag1 Flag2
Q2 123 20 - N
Q2 234 50 N -
Q2 345 50 - -
Thanks in Advance
try below:
d1:
load * inline [
Qtr,ID,Weight,Flag1,Flag2
Q1,123,10,,Y
Q1,123,20,,N
Q1,234,20,Y,
Q1,345,50,,
];
Qualify *;
Load *
Resident d1
where (Flag1 = 'Y' and Flag2 <> 'N') OR
(Flag1 <> 'N' and Flag2 = 'Y') OR
(len(trim(Flag1)) = 0 and len(trim(Flag2)) = 0);
//------------------------------------------------------------------------//
d2:
load * inline [
Qtr,ID,Weight,Flag1,Flag2
Q1,123,10,,Y
Q1,123,20,,N
Q1,234,50,N,
Q1,345,50,,
];
Load *
Resident d2
where (d2.Flag1 = 'N' and d2.Flag2 <> 'Y') OR
(d2.Flag1 <> 'Y' and d2.Flag2 = 'N') OR
(len(trim(d2.Flag1)) = 0 and len(trim(d2.Flag2)) = 0);
Unqualify *;
you can remove Qualify *; statement and delete the source tables if you dont need them.
What logic are you using while showing rows with same ID ?
For eg, in 1st table, you have 2 rows with same ID '123' with weights 10 & 20. But you want to show only the row with weight 10.
But in 2nd case, you have shown row with weight 20. what criteria are you setting for the expected output ?
Regards,
Aditya
try below:
d1:
load * inline [
Qtr,ID,Weight,Flag1,Flag2
Q1,123,10,,Y
Q1,123,20,,N
Q1,234,20,Y,
Q1,345,50,,
];
Qualify *;
Load *
Resident d1
where (Flag1 = 'Y' and Flag2 <> 'N') OR
(Flag1 <> 'N' and Flag2 = 'Y') OR
(len(trim(Flag1)) = 0 and len(trim(Flag2)) = 0);
//------------------------------------------------------------------------//
d2:
load * inline [
Qtr,ID,Weight,Flag1,Flag2
Q1,123,10,,Y
Q1,123,20,,N
Q1,234,50,N,
Q1,345,50,,
];
Load *
Resident d2
where (d2.Flag1 = 'N' and d2.Flag2 <> 'Y') OR
(d2.Flag1 <> 'Y' and d2.Flag2 = 'N') OR
(len(trim(d2.Flag1)) = 0 and len(trim(d2.Flag2)) = 0);
Unqualify *;
you can remove Qualify *; statement and delete the source tables if you dont need them.