Need help with dgraph query

Hi August,

Thank you for the response. I have completed the tutorial(in fact many times already: sweat_smile:). My query is to get the “number of distinct items purchased by each customer”. The query posted by you gives me the list of all items purchased by each customer. But it is missing the aggregation(count) part and distinct part. To help you in visualizing my requirement better, I will give an example.

consider 2 customers who placed 2 orders each. lets say that customer A ordered item X and item Y in first order and item Y and item Z in other order, then the distinct items ordered by him are:- item X, item Y, and item Z and the count is 3.

Let’s say that customer B bought item Z in both of his orders, then the number of distinct items ordered by him is 1.
final response required is:-
A : 3
B: 1

for 1 customer I can do this

{
	var(func: eq(customer_name,"A")) {
	customer_name
	did_order {
		order.date
		item_list as order.item
	}
       item_count(func: uid(item_list)){
         final_count : count(uid)
       }
}

I want to know how to do the same when I’m starting with has(customer.name) .i.e when i want to do it for everyone at once.

now, drifting away from layman terms. the challenge I’m facing is " when there are multiple nodes at the root level, I would like to be able to store query variables (uid_lists) whose scope is local. i.e separate uid_list for each node at root level "