Answer the question
In order to leave comments, you need to log in
How to create unique keys for many-to-many relationship in one table?
Friends, hello!
Today, at one of the interviews, the question was asked:
There is a table that has a many-to-many relationship in itself, for example, the application id and the client's phone number are taken. The client can register several phones in one application, as well as several applications for one phone (for example, an application in a tablet and a phone).
The table looks like:
ID | Phone
------------
11 | 965
17 | 982
14 | 913
14 | 928
43 | 928
11 | 982
13 | 917
The result of the work should be the following:
ID | phone | Unique_ID
--------------------------
11 | 965 | 1
17 | 982 | one
14 | 913 | 2
14 | 928 | 2
43 | 928 | 2
11 | 982 | 1
13 | 917 | 3
I hope I explained correctly)
What tools and how can this be done? The hint goes to python, mapreduce most likely
Answer the question
In order to leave comments, you need to log in
Your task is to enumerate the connected components of the graph consisting of vertices of the form a_{ID} and p_{PHONE}. Each row of the table is an edge of the graph.
what is their uniqueness if it is not unique in your final data set?
And there is no logic at all, according to what principle one group (unique id) is obtained for different data sets
14 | 913 | 2
14 | 928 | 2
43 | 928 | 2
In short, the output is some kind of porridge.
We need the logic of work normally described, and not what was and what has become.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question