Click here to Skip to main content
14,828,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a mysql table with fields

id user_id refer_user_id position

1 1 10 left
2 1 12 left
3 1 16 right


i want pair count for above table data , condition is one left and one right is one pair.

if i see above data here for user_id 1 three referral two positions are left and one position is right so as per condition i need return pair count 1, it will count only paired row(one left and one right is one pair) and will skip unpaired row / count.


any method you can use means in single mysql query you can do or by using php .

What I have tried:

i am confused how to do, i am trying mysql with group by , or count its returning result that not the correct that i want
Posted
Updated 12-Feb-21 22:34pm

1 solution

See here: SQL GROUP BY Statement[^] combine that with the appropriate aggregate function: SQL COUNT(), AVG() and SUM() Functions[^] and it'll do exactly what you want.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900