Yesterday someone posted a set of queries for interviews, all centered on answering business-like questions from database.
Today this post is hidden behind some “subscribe to read more" thing, so I will not even link it, but one question there caught my eye.
Since I can't copy paste the text, I'll try to write what I remember:
Given table sessions, with columns: user_id, login_time, and country_id, list all cases where single account logged to the system from more than one country within 2 hour time frame.
The idea behind is that it would be a tool to find hacked account, based on idea that you generally can't change country within 2 hours. Which is somewhat true.
Solution in the blogpost suggested joining sessions table with itself, using some inequality condition. I think we can do better…
Continue reading Who logged to system from multiple countries in 2 hours?