Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Assume I have a following in a MySql table: enter image description here

In this table the values for some of the records (sub 1-7) may identical or near-identical; as in case of Bill, Bush and Kate. I want to sort the table based on percentage relatedness among the records. As you can see Bill and Kate are nearly identical, which is followed by Bush. The table should be sorted in this order: Bill, Bush, Gate etc. The table contains over 200 records, with many having near-identical values. How can this be done in php? Any ideas?

share
add comment

1 Answer

Try

select * 
from your_table
order by abs(sub1 - avg(sub1)) + 
         abs(sub2 - avg(sub2)) + 
         abs(sub3 - avg(sub3)) + 
         abs(sub4 - avg(sub4)) + 
         abs(sub5 - avg(sub5)) + 
         abs(sub6 - avg(sub6)) + 
         abs(sub7 - avg(sub7)) + 
share
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.