A Database Query Problem

A database query problem for those who are interested:

There is a table with two columns: userId, time (many to many relationship)
For every pair of userIds, if any two time difference of two users is less than 20 minutes, then the pair will get a point.
Now need to find out the pair with highest points.

For example:

userId time
a 20
a 120
a 230
b 30
b 110
b 260
c 30
c 120
c 245

Then points of pair:
ab = 2
ac = 3
bc = 3

PS: This query may be used for data mining and/or artificial intelligence.

PS: It can also be used for trolling 3:)

PS: Idea courtesy – Nipa Afroz

Advertisements

Want to share your views? Please do reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s