Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
renjithpl
Specialist
Specialist

Filter records

Hi guys,

I have a table like this

   

FruitsID
Apple1
Mango1
Orange1
Apple2
Mango2
Orange3

I have to only show records with Apple and Mango when an id has all three combination (apple, mango and orange) need to eliminate orange.

but when an id has only Orange, I have to retain the orange.

Any idea.

?

Renjith

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Temp:

Load * Inline

[

  Fruits, ID

  Mango, 1

  Orange, 1

  Apple, 1

  Apple, 2

  Mango, 2

  Orange, 3

];

Left Join (Temp)

Load

  ID,

  Count(DISTINCT Fruits) as TotalFruits

Resident Temp

Where Match(Fruits,'Mango','Orange','Apple')

Group By ID;

Final:

Load

  ID,

  Fruits

Resident Temp

Where (TotalFruits <> 3 or Fruits <> 'Orange');

Drop Table Temp;

View solution in original post

4 Replies
MK_QSL
MVP
MVP

What is the output for your example you are expecting?

renjithpl
Specialist
Specialist
Author

   

FruitsID
Apple1
Mango1
Apple2
Mango2
Orange3
MK_QSL
MVP
MVP

Temp:

Load * Inline

[

  Fruits, ID

  Mango, 1

  Orange, 1

  Apple, 1

  Apple, 2

  Mango, 2

  Orange, 3

];

Left Join (Temp)

Load ID, IF(WildMatch(AllFruits,'*Apple|Mango|Orange*'),1,0) as Flag;

Load ID, Concat(DISTINCT Fruits, '|') as AllFruits Resident Temp Group By ID;

Final:

Load ID, Fruits Resident Temp

Where (Flag = 0 or Fruits <> 'Orange');

Drop Table Temp;

MK_QSL
MVP
MVP

Temp:

Load * Inline

[

  Fruits, ID

  Mango, 1

  Orange, 1

  Apple, 1

  Apple, 2

  Mango, 2

  Orange, 3

];

Left Join (Temp)

Load

  ID,

  Count(DISTINCT Fruits) as TotalFruits

Resident Temp

Where Match(Fruits,'Mango','Orange','Apple')

Group By ID;

Final:

Load

  ID,

  Fruits

Resident Temp

Where (TotalFruits <> 3 or Fruits <> 'Orange');

Drop Table Temp;