Skip to main content
Announcements
Qlik Community Office Hours - Bring your Ideation questions- May 15th, 11 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If Statement

What is wrong?

The question works if I comment "if(c.country_id='1', 'SE', 'annat_land') as Land,"

Buyers:

LOAD * ;

SQL select cu.email as [Email Address],

max(o.created_at) as last_order_date,

cu.identity_number,

if(c.country_id='1', 'SE', 'other') as Country,

c.country_id

from carts c

left join customers cu on c.customer_id=cu.id

left join orders o on o.cart_id=c.id

where o.created_at>'2010-01-01 00:00:00.000'

and o.order_status_id>'100'

group by cu.email,cu.identity_number,c.country_id;

/Julia

1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

Hi Julia,

The line where you create the Country (Land?) field is not an aggregated (eg SUM) or single (eg MAX) value, so that column needs to be included in the group by clause.  Alternatively you can move the creation of that field into the preceding LOAD portion (eg LOAD*, if(country_id='1' ...)

flipside

View solution in original post

3 Replies
flipside
Partner - Specialist II
Partner - Specialist II

Hi Julia,

The line where you create the Country (Land?) field is not an aggregated (eg SUM) or single (eg MAX) value, so that column needs to be included in the group by clause.  Alternatively you can move the creation of that field into the preceding LOAD portion (eg LOAD*, if(country_id='1' ...)

flipside

martin59
Specialist II
Specialist II

Hi Julia,

Could you try this :

if(c.country_id=1, 'SE', 'annat_land') as Land,

I removed quotes



Hope that helps you

Martin

Not applicable
Author

Thanks!