Skip to content
Advertisement

Keeping tally of users who meet more than one condition

I have a database of users (represented by visitorId) who belong to a specific channel and exhibited certain behaviors, as logged under the eCommerceActionType field.

channel visitorId eCommerceActionType
Social 1 page_view
Social 1 added_to_cart
Referral 2 added_to_cart
Referral 2 purchased
Social 3 page_view
Social 3 added_to_cart
Social 3 purchased
Direct 4 page_view
Direct 4 added_to_cart

I want to output a table that keeps a tally of users who both “added_to_cart” and “purchased” by channel. So the result should look like:

Channel cart_and_purchase
Social 1
Referral 1
Direct 0

What is the most efficient query to produce this table?

Appreciate any help I can get.

Advertisement

Answer

You can use two levels of aggregation:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement