Where clause queries in KQL

I am using ELK stack to perform some analysis on my data. My index pattern has 2 types of data

  1. The ID of the product clicked
  2. The ID of the product sold

I would like to first find all the IDs sold out and based on that find the number of times that ID was clicked.
1, clicked
1, sold
2, clicked
2, clicked
2, sold
3. clicked

So in this data-> ID1 and ID2 were sold. And ID1 was clicked once and ID2 was clicked twice.

I am unable to achieve this in KQL.