Skip to content
Advertisement

How to find the category that is both ordered & clicked by customer joining multiple tables?

I have these below 5 tables and I am trying to find customers that ordered from the same category they clicked. With a condition where order date should be greater than the click date

Table: customers

Table : orders

Table : clicks

Table : product

Table : dim

Expected results

c@gmail will be excluded because he ordered a different category than the one he clicked. I am not able to get how to fetch the data based on the category. I was only able to write a query to fetch if customers bought the same item they clicked. Any help is appreciated. This is the query i have to find exactly what customer clicked & bought the same pid.

Advertisement

Answer

1. t1: join between the customers table and the orders and product

2. t2: join between the customers table and the clicks and product

3. result join t1 to t2 with t1.cid = t2.cid and t1.categorty_id = t2.categorty_id

4. join t1 to dim


demo in db<>fiddle

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