Skip to content
Advertisement

Inner join with special conditions

Given an hourly table A with full records, e.g.:

And a subset B of it, e.g.

I want to keep only those records from A that are in B or at most 2hr behind the B subset, without duplication, e.g.

How can the result be achieved with an inner join, without duplication (in this case the hours 8&9) and preserving the right purchase values for the hours in B? (This is an MWE, assume multiple users and timestamps instead of hours)

Advertisement

Answer

This is a simple INNER join with the proper conditions in the ON clause:

You can add a WHERE clause if you want results for a specific user:

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