javasap-commerce-cloudflexible-search

Hybris relational FlexibleSearch selection


Hybris creates several carts for the user for the same base store. How to select users who have more than one cart per one store?

Later on I will sort them and remove the oldest one.

SELECT {u.code} as userCode,
       {c.code} as cartCode,
       {c.site} as cartSite
FROM {User as u join Cart as c on {u.pk} = {c.user}}
WHERE...

Solution

  • Use this one:

    select {u.pk}, {b.pk}, count(distinct({c.pk})) 
    from {
       user as u 
       join cart as c on {c.user} = {u.pk} 
       join basestore as b on {b.pk} = {c.store}
    } 
    group by {u.pk}, {b.pk} 
    having count(distinct({c.pk})) > 1