Reputation: 249
I have table:
I want to make in script to load data this:
(if((color = 'blue' or color = 'green' or color = 'red') and place = 'A','GROUP A') or
if((color = 'yellow' or color = 'red' or color = 'blue') and place = 'B','GROUP B')) as allPl
but when create list my allPl is empty.
Any idea?
Upvotes: 1
Views: 2952
Reputation: 77
you can try with match() or wildmatch() or mixmatch() to reduce your expression.
try like,
if(match(color,'blue','green','red') and place='A','Group A', if(match(color,'yellow','red','blue') and place='B','Group B') ) as appPl
Regards,
Upvotes: 0
Reputation: 1
You can also use this solution.
map_allPl:
mapping
load
color & '@@separator@@' & place AS IN
,allPl AS OUT
inline
[color,place,allPl
blue,A,GROUP A
green,A,GROUP A
red,A,GROUP A
yellow,B,GROUP B
red,B,GROUP B
blue,B,GROUP B];
table:
load
*
,applyMap('map_allPl',color & '@@separator@@' & place,'nd') AS allPl
inline
[id,color,place
1,blue,A
2,green,A
3,red,A
4,yellow,B
5,red,B
6,blue,B
];
Upvotes: 0
Reputation: 932
The most simple solution, I think, will be
If(mixmatch(id,'blue','green','red') and place='A','Group A',
If(mixmatch(id,'blue','green','yellow') and place='B','Group B')) as allPl
Upvotes: 1
Reputation: 5012
You need to nest the if
statements to get the result.
if( condition1 = true, result1,
if(condition2 = true <at this point condition1 = false>, result2 ...
For your case:
if( color = 'blue'
or color = 'green'
or color = 'red','GROUP A',
if( color = 'yellow'
or color = 'red'
or color = 'blue','GROUP B')
) as allPl
The script above will produce the following result:
But i'm not sure that this is the result you want. As you can see from the image above only the yellow
value will have GROUP B
assigned using this approach.
Leave a comment is this is the case
Upvotes: 0