Skip to content
Advertisement

How to return only those customer_id who visited Santa Clara after visiting Milpitas or #5 after visiting #2

How can I return the customer_id of those customers who visited Santa Clara after visiting Milpitas or #5 after visiting #2?

Advertisement

Answer

Use conditional aggregation with a having clause:

Your statement is that the customer when to after Santa Clara after Milpitas. This leaves open the possibility that the customer visited both locations multiple times.

To meet the condition as stated, you need to know that some visit to Santa Clara was later than some visit to Milpitas (at least that is how I interpret the question). Well, that is true if the lastest visit to Santa Clara was after the earliest visit to Milpitas.

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