select - Filtering out unique rows in MySQL -


so i've got large amount of sql data looks this:

user | src | dst 1    | 1   | 1 1    | 1   | 1 1    | 1   | 2 1    | 1   | 2 2    | 1   | 1 2    | 1   | 3 

i want filter out pairs of (src,dst) unique to 1 user (even if user has duplicates), leaving behind pairs belonging more 1 user:

user | src | dst 1    | 1   | 1 1    | 1   | 1 2    | 1   | 1 

in other words, pair (1,2) unique user 1 , pair (1,3) user 2, they're dropped, leaving behind instances of pair (1,1).

edit: clarify, not interested in pairs filtered out, need all rows pairs not unique.

any ideas? answers question below can find non-unique pairs, sql-fu doesn't suffice handle complication of requiring belong multiple users well.

how select non "unique" rows

my solution (tested):

select user, src, dst, count(user) num_of_users test group src, dst having num_of_users = 1 

edit: following code produces results provided in example.

select test.user, test.src, test.dst test inner join (     select user, src, dst, count(distinct user) num_of_users     test     group src, dst     having num_of_users > 1 ) inner_sql using(src, dst) 

is solution 1 looking for? how performance?


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -