我有一个看起来像的函数
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。我想做的是按该查询列表中排在第一位的团队对结果进行排序。
这可能吗?
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";
}
SELECT team_name
FROM myteam
WHERE team_id IN ($team1,$team2)
ORDER
BY FIELD(team_id,$team1,$team2);
试试这个,
function myFunction($team1, $team2) {
$query = "select team_name from myteam where (team_id=$team1 OR team_id=$team2) ORDER BY team_id DESC";
}