按频率排序的多个mysql查询

时间:2012-11-08 23:13:35

标签: mysql

  • 姓名年龄工作眼睛

  • John young home black

  • 迈克年轻工厂蓝

  • 欧文老家黑

  • Marie young home blue

  • 泰迪老厂绿色

在html中,多个复选框形式搜索term1 = young,term2 = home,term3 = blue

//display all combination order from first in table<br>
$sql = mysql_query("select(Name) from Table where Age = '$term1' or Work = '$term2' or Eyes = '$term3'");

我需要按频率按顺序显示。在我的情况下(首先是结果)必须是玛丽

哪些功能以及如何执行此操作?

1 个答案:

答案 0 :(得分:2)

SELECT   *
FROM     my_table
WHERE    (Age = 'young')
      OR (Work = 'home')
      OR (Eyes = 'blue')
ORDER BY (Age = 'young')
       + (Work = 'home')
       + (Eyes = 'blue') DESC

sqlfiddle上查看。