0

我有一个看起来像的函数

function myFunction($team1, $team2) {
$query = "select team_name from myteam where team_id=$team1 or team_id=$team2";
}

结果总是按较低的team_id排序,所以如果是

myFunction(12, 8);

返回将是 team8 然后是 team12。我想做的是按该查询列表中排在第一位的团队对结果进行排序。

这可能吗?

4

3 回答 3

2
function myFunction($team1, $team2) {
$query = "select team_name from myteam where team_id=$team1 or team_id=$team2 ORDER BY (team_id=$team1) DESC, team_id";
}
于 2013-04-23T06:59:11.130 回答
1
SELECT team_name 
  FROM myteam 
 WHERE team_id IN ($team1,$team2)
 ORDER
    BY FIELD(team_id,$team1,$team2);
于 2013-04-23T08:25:48.073 回答
0

试试这个,

 function myFunction($team1, $team2) {
 $query = "select team_name from myteam where (team_id=$team1 OR team_id=$team2) ORDER BY team_id DESC";
 }
于 2013-04-23T07:29:13.553 回答