php - MySQL count rows where a=b and b=a -


This is the first time I have asked a question. This is the first time that I can not find what I am seeing and I think I am being mad because it should be simple!

Assume that you have a MySQL table, 'T' with two columns 'A', 'B'.

  AB --- 1 2 2 1 1 3 3 1 2 4   

I like to count a variable given interrelationship. Therefore if I should

  X = 1   

return it

  2   

Because 1, 2 and 2, 1 is present, and 1, 3 and 3, 1 exists, however, supply

  x = 2   

It should be returned

  1   

because 1, 2 and 2, 1 exists but no other rows, where 2 = n AND N = 2

I hope this is clear! And sorry if it is easy, I think the brain is getting freeze .. Cheers!

This will work (but if you have a line with (n, n) then also Will be counted as a mutual relationship):

  select count (*) Join TT1 t1.B = T2.A on T2 where t1.A =? And t2.b =?   

(assign values ​​to both standards)

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -